Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Inspector support #852

Closed
wants to merge 1 commit into from
Closed

Add Inspector support #852

wants to merge 1 commit into from

Conversation

zikaari
Copy link
Contributor

@zikaari zikaari commented Jul 5, 2023

This is take 1 at adding working Inspector support. Feedback/improvements welcome

Copy link
Contributor

@oscb oscb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is huge! 💯

I left a few comments. The only blocker imo is about adding socket.io directly as a dependency to core. I think we should explore spinning this up as a standalone package.
Aside from that it looks great.

Great job!

@@ -272,6 +273,8 @@ export class SegmentClient {

// flush any stored events
this.flushPolicyExecuter.manualFlush();

await Inspector.init();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this enable only when running while on debug? You can use this.config.debug to check

Inspector.trace({
timestamp: new Date().toISOString(),
stage: 'triggered',
event: event as never,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

event as never ?

query: {
platform: Platform.OS,
sdk: 'React Native',
appName: await nativeModule.getAppName(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could receive this as an argument to decouple it from the NativeModules

"@segment/sovran-react-native": "^1",
"deepmerge": "^4.2.2",
"js-base64": "^3.7.2",
"socket.io-client": "^4.6.2",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concern right now is that socket.io seems to be a huge library. 1MB+ in size.

Metro doesn't do Tree Shaking so it can be a lot of imports that we don't use (and possibly users won't either in prod builds)

Can we refactor this into a standalone package before publishing it?

An idea is to dispatch events at all the places where we currently do a inspector.trace call, the inspector can then subscribe to those events. It could retain the same APIs and TraceData object for simplicity.

If we refactor it into a standalone plugin lib we could even dismiss the debug check I mentioned in a comment below as we could refer people to only install it as devDependency.

Comment on lines +48 to +53
const status = (await this.socket.emitWithAck(
'inspector-api',
sid,
method,
args
)) as number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to handle any errors in this promise?

const traces = this.queue;

const isSuccessfullBootup =
(await send('start', {})) && (await sendTraces(traces));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious as to why send the current queue here instead of as the first "prevBatch".

Is it common to experience disconnects in the socket during this step?

@@ -76,6 +77,15 @@ export class Timeline {
}
}

Inspector.trace({
timestamp: new Date().toISOString(),
stage: 'delivered',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the stage values an enum? do they show up differently in the inspector depending on the value here?

stage: 'delivered',
event: result as never,
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
id: incomingEvent.messageId!,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I don't think this should ever ever happen, but maybe use result instead of incomingEvent as technically a plugin can change the messageId

@@ -103,6 +113,21 @@ export class Timeline {
} else {
await pluginResult;
}

if ([PluginType.before, PluginType.enrichment].includes(type)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also notify for after plugins? maybe not as an enriched but as a special stage?

if ([PluginType.before, PluginType.enrichment].includes(type)) {
Inspector.trace({
timestamp: new Date().toISOString(),
stage: 'enriched',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about triggering this for all plugin types, switch the stage depending on the type.

As for the name of the plugin it could pull the key for the Destinations (it's the only one that is enforced at the moment):

let stageMap = {
  PluginType.enrichment: "enriched",
  PluginType.before: "enriched",
  PluginType.destination: "delivered",
  PluginType.after: "after",
// ...
};
const stage = stageMap[type];

 Inspector.trace({
	timestamp: new Date().toISOString(),
	stage: stage,
    event: result as never,
    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
    id: event.messageId!,
    enricher: {
	 name: (type === PluginType.destination) ? plugin.key : undefined,
      type: PluginType[type],
    },
})

@alanjcharles alanjcharles deleted the add_inspector_support branch May 20, 2024 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants