Closed 10xLaCroixDrinker closed 6 months ago
Hi @10xLaCroixDrinker, thanks for the feature request!
This does sound like it could be useful and it looks like there has been some talk on the otel-js repo about handling shared attributes (https://github.com/open-telemetry/opentelemetry-js/issues/4274).
I do think in this case, the logic here would be better suited in a SpanProcessor
though.
Sharing parent attributes could be achieved like so:
class ShareParentAttrsProcessor extends NoopSpanProcessor {
onStart (span, parentContext) {
// Check if the span was created by this plugin...
if (span.instrumentationLibrary.name === '@autotelic/fastify-opentelemetry') {
const parentSpan = api.trace.getSpan(parentContext)
if (parentSpan?.attributes) {
span.setAttributes(parentSpan.attributes)
}
}
}
}
I've pushed a branch with a working example of the above, If you'd like try it out locally -> https://github.com/autotelic/fastify-opentelemetry/blob/eg-propagate-attrs/example/opentelemetry.js
Thanks @HW13
I'd be interested in a feature that allowed you to propagate the span attributes that were added to the parent span down to the child spans created using
request.openTelemetry().tracer
. I was thinking something along these lines:This uses a new option
propagateSpanAttributes
and whentrue
(defaultfalse
), gets the attributes from the parent span created byfastify-opentelemetry
and applies them to any spans you create by extendingtracer.startSpan
. If there is no match for the request in thecontextMap
(e.g. when called in anonResponse
hook), it usesformatSpanAttributes.request
to create the attributes.What do you think?