spotlight
spotlight copied to clipboard
otel support
I'm using otel for instrumentation. and would love to have spotlight in my app. I suppose I shuold be able to write implementation of SpanExporter (from "@opentelemetry/sdk-trace-base") that forwards spans to the sidecar and get traces show up in the overlay.
It's ok if otel support is not on the roadmap I could implement it myself, tho if you point me to where sentry sdk is sending events to the sidecar so i can send similar events form the span exporter would love that.
I tried this:
import type { SpanExporter } from "@opentelemetry/sdk-trace-base";
import {
serializeEnvelope,
type SpanEnvelope,
type SpanItem,
} from "@sentry/core";
export class SpotlightSpanExporter implements SpanExporter {
export(spans: ReadableSpan[], resultCallback?: (result: ExportResult) => void): void {
const spanEnvelope: SpanEnvelope = [
{},
spans.map(
(span): SpanItem => [
{
type: "span",
},
{
data: {
"sentry.op": span.name,
...span.attributes,
},
op: span.name,
parent_span_id: span.parentSpanId,
span_id: span.spanContext().spanId,
start_timestamp: hrTimeToMilliseconds(span.startTime),
timestamp: hrTimeToMilliseconds(span.endTime),
status: span.status.code.toString(),
trace_id: span.spanContext().traceId,
links: span.links.map(
(link): SpanLinkJSON => ({
span_id: link.context.spanId,
trace_id: link.context.traceId,
attributes: link.attributes,
}),
),
},
],
),
];
void fetch("http://localhost:8969/stream", {
method: "POST",
body: serializeEnvelope(spanEnvelope),
headers: {
"Content-Type": "application/x-sentry-envelope",
},
mode: "cors",
}).then((res) => {
if (resultCallback) {
resultCallback({
code: res.status >= 200 && res.status < 400 ? ExportResultCode.SUCCESS : ExportResultCode.FAILED,
});
}
});
}
shutdown(): Promise<void> {
return Promise.resolve();
}
forceFlush(): Promise<void> {
return Promise.resolve();
}
}
I did saw envelopes in the overlay tho not in traces section
@safareli our latest SDKs support OTEL natively, why not use those?