UNPKG

1.7 kBJavaScriptView Raw
1"use strict";
2/*!
3 * Copyright 2020 Google LLC
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16Object.defineProperty(exports, "__esModule", { value: true });
17exports.createSpan = void 0;
18const api_1 = require("@opentelemetry/api");
19// eslint-disable-next-line @typescript-eslint/no-var-requires
20const PKG = require('../../package.json');
21/**
22 * @internal
23 * Instantiates a Opentelemetry tracer for the library
24 */
25const libraryTracer = api_1.trace.getTracer('@google-cloud/pubsub', PKG.version);
26/**
27 * Creates a new span with the given properties
28 *
29 * @param {string} spanName the name for the span
30 * @param {Attributes?} attributes an object containing the attributes to be set for the span
31 * @param {SpanContext?} parent the context of the parent span to link to the span
32 */
33function createSpan(spanName, kind, attributes, parent) {
34 return libraryTracer.startSpan(spanName, {
35 // set the kind of the span
36 kind,
37 // set the attributes of the span
38 attributes: attributes,
39 }, parent ? api_1.trace.setSpanContext(api_1.context.active(), parent) : undefined);
40}
41exports.createSpan = createSpan;
42//# sourceMappingURL=opentelemetry-tracing.js.map
\No newline at end of file