-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
tracing.ts
37 lines (32 loc) · 1013 Bytes
/
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
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { getTracer } from "@azure/core-tracing";
import { Span, SpanOptions, SpanKind } from "@opentelemetry/types";
import { OperationTracingOptions } from "../StorageClient";
/**
* 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: SpanOptions = {
...tracingOptions.spanOptions,
kind: SpanKind.INTERNAL
};
const span = tracer.startSpan(`Azure.Storage.Blob.${operationName}`, spanOptions);
let newOptions = tracingOptions.spanOptions || {};
if (span.isRecording()) {
newOptions = {
...tracingOptions,
parent: span
};
}
return {
span,
spanOptions: newOptions
};
}