/
tracing.ts
40 lines (36 loc) · 1.17 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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { Span, SpanKind, SpanOptions as OTSpanOptions } from "@opentelemetry/api";
import { getTracer, SpanOptions, OperationTracingOptions } from "@azure/core-tracing";
/**
* Creates a span using the global tracer.
* @param name The name of the operation being performed.
* @param tracingOptions The options for the underlying http request.
*/
export function createSpan(
operationName: string,
tracingOptions: OperationTracingOptions = {}
): { span: Span; spanOptions: SpanOptions } {
const tracer = getTracer();
const spanOptions: OTSpanOptions = {
...tracingOptions.spanOptions,
kind: SpanKind.INTERNAL
};
const span = tracer.startSpan(`Azure.Storage.DataLake.${operationName}`, spanOptions);
span.setAttribute("az.namespace", "Microsoft.Storage");
let newOptions = tracingOptions.spanOptions || {};
if (span.isRecording()) {
newOptions = {
...tracingOptions.spanOptions,
parent: span.context(),
attributes: {
...spanOptions.attributes,
"az.namespace": "Microsoft.Storage"
}
};
}
return {
span,
spanOptions: newOptions
};
}