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

Prevent Azure SDK OT incompatibility to trigger errors #818

Merged
merged 2 commits into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion AutoCollection/diagnostic-channel/SpanParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ function filterSpanAttributes(attributes: SpanAttributes) {
}

export function spanToTelemetryContract(span: Span): (Contracts.DependencyTelemetry & Contracts.RequestTelemetry) & Contracts.Identified {
const id = `|${span.spanContext().traceId}.${span.spanContext().spanId}.`;
const spanContext = span.spanContext ? span.spanContext() : (<any>span).context(); // context is available in OT API <v0.19.0
const id = `|${spanContext.traceId}.${spanContext.spanId}.`;
const duration = Math.round(span["_duration"][0] * 1e3 + span["_duration"][1] / 1e6);
let peerAddress = span.attributes["peer.address"] ? span.attributes["peer.address"].toString() : "";

Expand Down
42 changes: 22 additions & 20 deletions AutoCollection/diagnostic-channel/azure-coretracing.sub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,29 @@ import { AsyncScopeManager } from "../AsyncHooksScopeManager";
let clients: TelemetryClient[] = [];

export const subscriber = (event: IStandardEvent<Span>) => {
const span = event.data;
const telemetry = SpanParser.spanToTelemetryContract(span);
const spanContext = span.spanContext();
const traceparent = new Traceparent();
traceparent.traceId = spanContext.traceId;
traceparent.spanId = spanContext.spanId;
traceparent.traceFlag = Traceparent.formatOpenTelemetryTraceFlags(spanContext.traceFlags);
traceparent.parentId = span.parentSpanId ? `|${spanContext.traceId}.${span.parentSpanId}.` : null;

AsyncScopeManager.with(span, () => {
clients.forEach((client) => {
if (span.kind === SpanKind.SERVER) {
// Server or Consumer
client.trackRequest(telemetry);
} else if (span.kind === SpanKind.CLIENT || span.kind === SpanKind.INTERNAL) {
// Client or Producer or Internal
client.trackDependency(telemetry);
}
// else - ignore producer/consumer spans for now until it is clear how this sdk should interpret them
try {
const span = event.data;
const telemetry = SpanParser.spanToTelemetryContract(span);
const spanContext = span.spanContext ? span.spanContext() : (<any>span).context(); // context is available in OT API <v0.19.0
const traceparent = new Traceparent();
traceparent.traceId = spanContext.traceId;
traceparent.spanId = spanContext.spanId;
traceparent.traceFlag = Traceparent.formatOpenTelemetryTraceFlags(spanContext.traceFlags);
traceparent.parentId = span.parentSpanId ? `|${spanContext.traceId}.${span.parentSpanId}.` : null;
AsyncScopeManager.with(span, () => {
clients.forEach((client) => {
if (span.kind === SpanKind.SERVER) {
// Server or Consumer
client.trackRequest(telemetry);
} else if (span.kind === SpanKind.CLIENT || span.kind === SpanKind.INTERNAL) {
// Client or Producer or Internal
client.trackDependency(telemetry);
}
// else - ignore producer/consumer spans for now until it is clear how this sdk should interpret them
});
});
});
}
catch (err) { { /** ignore errors */ } }
};

export function enable(enabled: boolean, client: TelemetryClient) {
Expand Down