Skip to content
This repository was archived by the owner on Oct 3, 2023. It is now read-only.

Commit d05169d

Browse files
Sent OC Web library type and version to OC agent (#57)
1 parent aa426cb commit d05169d

6 files changed

Lines changed: 56 additions & 9 deletions

File tree

packages/opencensus-web-core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export {Tracer} from './trace/model/tracer';
2121
export {Tracing} from './trace/model/tracing';
2222
export * from './trace/model/util';
2323
export * from './trace/model/attribute-keys';
24+
export {VERSION} from './version';
2425

2526
// Re-export types this uses from @opencensus/web-types.
2627
export {Annotation, Attributes, BufferConfig, CanonicalCode, Config, Exporter, ExporterConfig, HeaderGetter, HeaderSetter, Link, LinkType, Logger, MessageEvent, MessageEventType, Propagation, SpanContext, SpanEventListener, SpanKind, Status, TracerConfig, TraceState} from '@opencensus/web-types';
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Copyright 2019, OpenCensus Authors
3+
*
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+
*/
16+
17+
/**
18+
* The version of the @opencensus/web-core library. This is sent as metadata
19+
* with the written traces by the @opencensus/web-exporter-ocagent library.
20+
*/
21+
export const VERSION = '0.0.1';

packages/opencensus-web-exporter-ocagent/src/api-types.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,26 @@ export interface Node {
6666
attributes?: {[key: string]: string};
6767
}
6868

69+
/** Unspecified library info language. */
70+
export type LanguageUnspecified = 0;
71+
/** Indicates that the spans were created by OpenCensus Web. */
72+
export type LanguageWebJs = 10;
73+
/**
74+
* OpenCensus language used to create the spans. Most of the options are
75+
* omitted since the spans produced by OpenCensus Web are always from the Web JS
76+
* library.
77+
*/
78+
export type LibraryInfoLanguage = LanguageUnspecified|LanguageWebJs;
79+
80+
/** Information on OpenCensus library that produced the spans/metrics. */
6981
export interface LibraryInfo {
70-
/**
71-
* TODO(draffensperger): Get additional language option for web JavaScript,
72-
* and then set the library version here.
73-
*/
82+
/** Language of OpenCensus Library. */
83+
language?: LibraryInfoLanguage;
7484

85+
/** Version of Agent exporter of Library. */
7586
exporterVersion?: string;
7687

88+
/** Version of OpenCensus Library. */
7789
coreLibraryVersion?: string;
7890
}
7991

packages/opencensus-web-exporter-ocagent/src/ocagent.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,20 @@
1414
* limitations under the License.
1515
*/
1616

17-
import {Exporter, ExporterConfig, RootSpan} from '@opencensus/web-core';
17+
import {Exporter, ExporterConfig, RootSpan, VERSION} from '@opencensus/web-core';
1818

1919
import {adaptRootSpan} from './adapters';
2020
import * as apiTypes from './api-types';
2121
import {ExporterBuffer} from './exporter-buffer';
2222
import {EXPORTER_VERSION} from './version';
2323

24+
/**
25+
* Enum value for LibraryInfo.Language that indicates to the OpenCensus Agent
26+
* that the generated spans/metrics are from the Web JS OpenCensus libary. See:
27+
* https://github.com/census-instrumentation/opencensus-proto/blob/master/src/opencensus/proto/agent/common/v1/common.proto
28+
*/
29+
const WEB_JS_LIBRARY_LANGUAGE: apiTypes.LanguageWebJs = 10;
30+
2431
// The value of XMLHttpRequest `readyState` property when the request is done.
2532
const XHR_READY_STATE_DONE = 4;
2633

@@ -98,9 +105,9 @@ export class OCAgentExporter implements Exporter {
98105
identifier: {hostName: location.host},
99106
serviceInfo: {name: this.config.serviceName},
100107
libraryInfo: {
108+
language: WEB_JS_LIBRARY_LANGUAGE,
101109
exporterVersion: EXPORTER_VERSION,
102-
// TODO(draffensperger): Set coreLibraryVersion here once there is an
103-
// OpenCensus web core library established.
110+
coreLibraryVersion: VERSION,
104111
},
105112
attributes: this.config.attributes,
106113
};

packages/opencensus-web-exporter-ocagent/src/version.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
/**
18-
* The version of the opencensus-web-exporter-ocagent library. This will be
18+
* The version of the @opencensus/web-exporter-ocagent library. This will be
1919
* sent as metadata with the written traces.
2020
*/
2121
export const EXPORTER_VERSION = '0.0.1';

packages/opencensus-web-exporter-ocagent/test/test-ocagent.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import * as webCore from '@opencensus/web-core';
1818

1919
import {OCAgentExporter} from '../src';
2020
import * as apiTypes from '../src/api-types';
21+
import {EXPORTER_VERSION} from '../src/version';
22+
2123
import {mockGetterOrValue, restoreGetterOrValue} from './util';
2224

2325
const BUFFER_SIZE = 1;
@@ -107,7 +109,11 @@ describe('OCAgentExporter', () => {
107109
node: {
108110
identifier: {hostName: window.location.host},
109111
serviceInfo: {name: 'testService'},
110-
libraryInfo: {exporterVersion: '0.0.1'},
112+
libraryInfo: {
113+
language: 10,
114+
coreLibraryVersion: webCore.VERSION,
115+
exporterVersion: EXPORTER_VERSION,
116+
},
111117
attributes: {serviceAddr1: 'a'},
112118
},
113119
spans: apiSpans,

0 commit comments

Comments
 (0)