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

Commit 526023e

Browse files
authored
Export package version [core] (#131)
* Exports the current package version from the root level. This allows users of this module to read the version of the library that has been loaded. * The `opencensus-exporter-ocagent` has been updated to support the newly exported version.
1 parent 88cb909 commit 526023e

3 files changed

Lines changed: 33 additions & 3 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
/**
3+
* Copyright 2018, OpenCensus Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
type Package = {
19+
version: string;
20+
};
21+
22+
// Load the package details. Note that the `require` is performed at runtime,
23+
// which means the source files will be in the `/build` directory, so the
24+
// package path is relative to that location.
25+
const pjson: Package = require('../../../package.json');
26+
27+
// Export the core package version
28+
export const version: string = pjson.version;

packages/opencensus-core/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,6 @@ export * from './stats/types';
5555
// logger
5656
import * as logger from './common/console-logger';
5757
export {logger};
58+
59+
// version
60+
export * from './common/version';

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import * as protoLoader from '@grpc/proto-loader';
18-
import {Exporter, ExporterBuffer, ExporterConfig, logger, Logger, RootSpan, SamplerBuilder} from '@opencensus/core';
18+
import {Exporter, ExporterBuffer, ExporterConfig, logger, Logger, RootSpan, SamplerBuilder, version as coreVersion} from '@opencensus/core';
1919
import * as tracing from '@opencensus/nodejs';
2020
import * as grpc from 'grpc';
2121
import * as os from 'os';
@@ -91,8 +91,7 @@ export class OCAgentExporter implements Exporter {
9191
* Get node properties
9292
*/
9393
this.exporterVersion = require('../../package.json').version;
94-
this.coreVersion =
95-
require('../../node_modules/@opencensus/core/package.json').version;
94+
this.coreVersion = coreVersion;
9695
this.hostName = os.hostname();
9796
this.processStartTimeMillis = Date.now() - (process.uptime() * 1000);
9897

0 commit comments

Comments
 (0)