-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
tracing.ts
54 lines (47 loc) · 1.39 KB
/
tracing.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import { GetTokenOptions } from "@azure/core-http";
import { getTracer, OperationTracingOptions } from "@azure/core-tracing";
import { Span, SpanKind, SpanOptions as OTSpanOptions } from "@opentelemetry/api";
/**
* Creates a span using the global tracer.
* @param name - The name of the operation being performed.
* @param options - The options for the underlying http request.
*/
export function createSpan(
operationName: string,
options: GetTokenOptions = {}
): { span: Span; options: GetTokenOptions } {
const tracer = getTracer();
const tracingOptions: OperationTracingOptions = {
spanOptions: {},
...options.tracingOptions
};
const spanOptions: OTSpanOptions = {
...tracingOptions.spanOptions,
kind: SpanKind.INTERNAL
};
const span = tracer.startSpan(`Azure.Identity.${operationName}`, spanOptions);
span.setAttribute("az.namespace", "Microsoft.AAD");
let newOptions = options;
if (span.isRecording()) {
newOptions = {
...options,
tracingOptions: {
...tracingOptions,
spanOptions: {
...tracingOptions.spanOptions,
parent: span.context(),
attributes: {
...spanOptions.attributes,
"az.namespace": "Microsoft.AAD"
}
}
}
};
}
return {
span,
options: newOptions
};
}