Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Commit

Permalink
Merge branch 'main' into strict-prerelease
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan authored Jun 30, 2021
2 parents b24ab88 + fda0e6b commit 973c0ab
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 15 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@

All notable changes to this project will be documented in this file.

## 1.0.1

### :bug: Bug Fix

* [#96](https:/open-telemetry/opentelemetry-js-api/pull/96) chore: remove circular dependency ([@dyladan](https:/dyladan))

### Committers: 1

* Daniel Dyla ([@dyladan](https:/dyladan))

## 1.0.0

### :memo: Documentation

* [#89](https:/open-telemetry/opentelemetry-js-api/pull/89) chore: update upgrade guidelines ([@dyladan](https:/dyladan))

### :house: Internal

* [#90](https:/open-telemetry/opentelemetry-js-api/pull/90) chore: enable typescript 4.3 noImplicitOverride option ([@Flarna](https:/Flarna))

### Committers: 2

* Daniel Dyla ([@dyladan](https:/dyladan))
* Gerhard Stöbich ([@Flarna](https:/Flarna))

## 0.21.0

### :boom: Breaking Change
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
---
<p align="center">
<strong>
<a href="https://open-telemetry.github.io/opentelemetry-js">API Documentation<a/>
<a href="https://open-telemetry.github.io/opentelemetry-js-api">API Documentation<a/>
&nbsp;&nbsp;&bull;&nbsp;&nbsp;
<a href="https:/open-telemetry/opentelemetry-js/discussions">Getting In Touch (GitHub Discussions)<a/>
</strong>
Expand Down Expand Up @@ -105,6 +105,10 @@ Because the npm installer and node module resolution algorithm could potentially

## Upgrade Guidelines

### 0.21.0 to 1.0.0

No breaking changes

### 0.20.0 to 0.21.0

- [#78](https:/open-telemetry/opentelemetry-js-api/issues/78) `api.context.bind` arguments reversed and `context` is now a required argument.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opentelemetry/api",
"version": "0.21.0",
"version": "1.0.1",
"description": "Public API for OpenTelemetry",
"main": "build/src/index.js",
"module": "build/esm/index.js",
Expand Down
5 changes: 3 additions & 2 deletions src/api/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
registerGlobal,
unregisterGlobal,
} from '../internal/global-utils';
import { DiagAPI } from './diag';

const API_NAME = 'context';
const NOOP_CONTEXT_MANAGER = new NoopContextManager();
Expand Down Expand Up @@ -49,7 +50,7 @@ export class ContextAPI {
* @returns true if the context manager was successfully registered, else false
*/
public setGlobalContextManager(contextManager: ContextManager): boolean {
return registerGlobal(API_NAME, contextManager);
return registerGlobal(API_NAME, contextManager, DiagAPI.instance());
}

/**
Expand Down Expand Up @@ -93,6 +94,6 @@ export class ContextAPI {
/** Disable and remove the global context manager */
public disable() {
this._getContextManager().disable();
unregisterGlobal(API_NAME);
unregisterGlobal(API_NAME, DiagAPI.instance());
}
}
4 changes: 2 additions & 2 deletions src/api/diag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ export class DiagAPI implements DiagLogger {
);
}

return registerGlobal('diag', newLogger, true);
return registerGlobal('diag', newLogger, self, true);
};

self.disable = () => {
unregisterGlobal(API_NAME);
unregisterGlobal(API_NAME, self);
};

self.createComponentLogger = (options: ComponentLoggerOptions) => {
Expand Down
5 changes: 3 additions & 2 deletions src/api/propagation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
deleteBaggage,
} from '../baggage/context-helpers';
import { createBaggage } from '../baggage/utils';
import { DiagAPI } from './diag';

const API_NAME = 'propagation';
const NOOP_TEXT_MAP_PROPAGATOR = new NoopTextMapPropagator();
Expand Down Expand Up @@ -62,7 +63,7 @@ export class PropagationAPI {
* @returns true if the propagator was successfully registered, else false
*/
public setGlobalPropagator(propagator: TextMapPropagator): boolean {
return registerGlobal(API_NAME, propagator);
return registerGlobal(API_NAME, propagator, DiagAPI.instance());
}

/**
Expand Down Expand Up @@ -104,7 +105,7 @@ export class PropagationAPI {

/** Remove the global propagator */
public disable() {
unregisterGlobal(API_NAME);
unregisterGlobal(API_NAME, DiagAPI.instance());
}

public createBaggage = createBaggage;
Expand Down
9 changes: 7 additions & 2 deletions src/api/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
setSpan,
setSpanContext,
} from '../trace/context-utils';
import { DiagAPI } from './diag';

const API_NAME = 'trace';

Expand Down Expand Up @@ -63,7 +64,11 @@ export class TraceAPI {
*/
public setGlobalTracerProvider(provider: TracerProvider): boolean {
this._proxyTracerProvider.setDelegate(provider);
return registerGlobal(API_NAME, this._proxyTracerProvider);
return registerGlobal(
API_NAME,
this._proxyTracerProvider,
DiagAPI.instance()
);
}

/**
Expand All @@ -82,7 +87,7 @@ export class TraceAPI {

/** Remove the global tracer provider */
public disable() {
unregisterGlobal(API_NAME);
unregisterGlobal(API_NAME, DiagAPI.instance());
this._proxyTracerProvider = new ProxyTracerProvider();
}

Expand Down
7 changes: 4 additions & 3 deletions src/internal/global-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { diag } from '..';
import type { DiagAPI } from '../api/diag';
import { ContextManager } from '../context/types';
import { DiagLogger } from '../diag';
import { _globalThis } from '../platform';
Expand All @@ -25,14 +25,15 @@ import { isCompatible } from './semver';

const major = VERSION.split('.')[0];
const GLOBAL_OPENTELEMETRY_API_KEY = Symbol.for(
`io.opentelemetry.js.api.${major}`
`opentelemetry.js.api.${major}`
);

const _global = _globalThis as OTelGlobal;

export function registerGlobal<Type extends keyof OTelGlobalAPI>(
type: Type,
instance: OTelGlobalAPI[Type],
diag: DiagAPI,
allowOverride = false
): boolean {
const api = (_global[GLOBAL_OPENTELEMETRY_API_KEY] = _global[
Expand Down Expand Up @@ -77,7 +78,7 @@ export function getGlobal<Type extends keyof OTelGlobalAPI>(
return _global[GLOBAL_OPENTELEMETRY_API_KEY]?.[type];
}

export function unregisterGlobal(type: keyof OTelGlobalAPI) {
export function unregisterGlobal(type: keyof OTelGlobalAPI, diag: DiagAPI) {
diag.debug(
`@opentelemetry/api: Unregistering a global for ${type} v${VERSION}.`
);
Expand Down
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
*/

// this is autogenerated file, see scripts/version-update.js
export const VERSION = '0.21.0';
export const VERSION = '1.0.1';
2 changes: 1 addition & 1 deletion test/internal/global.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const api2 = require('../../src') as typeof import('../../src');

// This will need to be changed manually on major version changes.
// It is intentionally not autogenerated to ensure the author of the change is aware of what they are doing.
const GLOBAL_API_SYMBOL_KEY = 'io.opentelemetry.js.api.0';
const GLOBAL_API_SYMBOL_KEY = 'opentelemetry.js.api.1';

const getMockLogger = () => ({
verbose: sinon.spy(),
Expand Down
30 changes: 30 additions & 0 deletions test/internal/version.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import * as assert from 'assert';
import { VERSION } from '../../src/version';

describe('version', () => {
it('should have generated VERSION.ts', () => {
const pjson = require('../../package.json');
assert.strictEqual(pjson.version, VERSION);
});

it('prerelease tag versions are banned', () => {
// see https:/open-telemetry/opentelemetry-js-api/issues/74
assert.ok(VERSION.match(/^\d+\.\d+\.\d+$/));
});
});

0 comments on commit 973c0ab

Please sign in to comment.