Hook to add extra tags to auto instrumented XHR and fetch
E.g. right before around here (instrument_fetch.js#L190) we could run a hook/callback like:
tags = extraTagsHook(tags);
and the extraTagsHook would be passed in where the tracer is instantiated, e.g:
opentracing.initGlobalTracer(new lightstep.Tracer({
access_token : '{your_access_token}',
component_name : '{your_service_or_app_name}',
extraTagsHook: tags => {
tags['web.origin.pathname'] = window.location.pathname;
return tags;
}
}));
WDYT?
Cheers!
related https://github.com/lightstep/lightstep-tracer-javascript/issues/90
I like the idea, although I wonder about registering the callback in the tracer options. That said, we already do kinda non-standard things there so maybe it wouldn't be a huge deal...
@austinlparker I'm happy to add it anywhere else :) do you have any suggestions?
Cheers
Just speculating, but would it be possible to add these tags, without modifying lightstep-tracer-javascript itself, by setting up a Tracer that extends from the Lightstep Tracer and overrides the inject method? Similar to how we can inject our own headers.
In that method we have access to spanContext, format and carrier.
Perhaps spanContext gives us the option to add tags.
Looks like the spanContext is fairly limited:
https://github.com/opentracing/opentracing-javascript/blob/master/src/span_context.ts
What we need to access is the actual span (https://github.com/opentracing/opentracing-javascript/blob/master/src/span.ts).
Perhaps it would be useful to have this feature baked into lightstep-tracer.
But it could also be accomplished by the consumer, by wrapping globalTracer().startSpan() in a function that adds the custom tags. Unless you need context from the actual XHR/Fetch call, then the implementation needs to look different either way.
It seems like the latter suggestion (a wrapper around startSpan) could be a nice little package to put in opentracing-contrib for the entire community.
Yes SpanContext is a "child" of Span
I like the span wrapper idea.