You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
function getExporter():
| GrpcTraceExporter
| JsonTraceExporter
| ProtoTraceExporter {
switch (process.env.OTEL_EXPORTER_OTLP_PROTOCOL) {
case 'grpc':
return new GrpcTraceExporter()
case 'http/json':
return new JsonTraceExporter()
case 'http/proto':
return new ProtoTraceExporter()
case '':
return new ProtoTraceExporter()
case undefined:
return new ProtoTraceExporter()
case null:
return new ProtoTraceExporter()
}
throw new Error(
`Cannot get OTLP exporter for protocol ${process.env.OTEL_EXPORTER_OTLP_PROTOCOL}`,
)
}
import { BatchSpanProcessor, ReadableSpan } from '@opentelemetry/sdk-trace-base'
export class CustomSpanProcessor extends BatchSpanProcessor {
onEnd(span: ReadableSpan): void {
if (
// If this attribute is there it's always a string.
(span.attributes['some.attribute'] as string)?.startsWith(
'remove_me',
)
) {
return
}
super.onEnd(span)
}
}
So far this seems to work, but the issue is that in order to instantiate CustomSpanProcessor which inherits from BatchSpanProcessor, we have to pass it an exporter. To do that, we basically have to reimplement how the SDK sets up its exporter(s).
Is there a way of adding a custom SpanProcessor without losing the default that's created in BasicTracerProvider?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
We are trying to implement a custom
SpanProcessor
to filter out some spans with certain attributes.This is what we have so far:
So far this seems to work, but the issue is that in order to instantiate
CustomSpanProcessor
which inherits fromBatchSpanProcessor
, we have to pass it an exporter. To do that, we basically have to reimplement how the SDK sets up its exporter(s).Is there a way of adding a custom
SpanProcessor
without losing the default that's created inBasicTracerProvider
?Beta Was this translation helpful? Give feedback.
All reactions