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

Commit

Permalink
Merge remote-tracking branch 'origin/main' into span-context-rename
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan committed Apr 26, 2021
2 parents 991e550 + c1f302e commit 9538416
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 31 deletions.
45 changes: 38 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,39 @@

---
<p align="center">
<strong>
<a href="https://open-telemetry.github.io/opentelemetry-js">API Documentation<a/>
&nbsp;&nbsp;&bull;&nbsp;&nbsp;
<a href="https://github.com/open-telemetry/opentelemetry-js/discussions">Getting In Touch (GitHub Discussions)<a/>
</strong>
</p>

<p align="center">
<a href="https://github.com/open-telemetry/opentelemetry-js-api/releases">
<img alt="GitHub release (latest by date including pre-releases)" src="https://img.shields.io/github/v/release/open-telemetry/opentelemetry-js-api?include_prereleases&style=for-the-badge">
</a>
<a href="https://codecov.io/gh/open-telemetry/opentelemetry-js-api/branch/main/">
<img alt="Codecov Status" src="https://img.shields.io/codecov/c/github/open-telemetry/opentelemetry-js-api?style=for-the-badge">
</a>
<a href="https://github.com/open-telemetry/opentelemetry-js-api/blob/main/LICENSE">
<img alt="license" src="https://img.shields.io/badge/license-Apache_2.0-green.svg?style=for-the-badge">
</a>
<br/>
<a href="https://github.com/open-telemetry/opentelemetry-js-api/actions/workflows/docs.yaml">
<img alt="Build Status" src="https://github.com/open-telemetry/opentelemetry-js-api/actions/workflows/test.yaml/badge.svg?branch=main">
</a>
<a href="https://github.com/open-telemetry/opentelemetry-js-api/actions/workflows/test.yaml?query=branch%3Amain">
<img alt="Build Status" src="https://github.com/open-telemetry/opentelemetry-js-api/actions/workflows/docs.yaml/badge.svg">
</a>
</p>

---

# OpenTelemetry API for JavaScript

[![NPM Published Version][npm-img]][npm-url]
[![dependencies][dependencies-image]][dependencies-url]
[![devDependencies][devDependencies-image]][devDependencies-url]
[![Apache License][license-image]][license-image]

This package provides everything needed to interact with the OpenTelemetry API, including all TypeScript interfaces, enums, and no-op implementations. It is intended for use both on the server and in the browser.

Expand Down Expand Up @@ -50,7 +80,7 @@ const tracer = trace.getTracer(name, version);
// Trace your application by creating spans
async function operation() {
const span = tracer.startSpan("do operation");

// mock some work by sleeping 1 second
await new Promise((resolve, reject) => {
setTimeout(resolve, 1000);
Expand All @@ -73,11 +103,13 @@ main();

Because the npm installer and node module resolution algorithm could potentially allow two or more copies of any given package to exist within the same `node_modules` structure, the OpenTelemetry API takes advantage of a variable on the `global` object to store the global API. When an API method in the API package is called, it checks if this `global` API exists and proxies calls to it if and only if it is a compatible API version. This means if a package has a dependency on an OpenTelemetry API version which is not compatible with the API used by the end user, the package will receive a no-op implementation of the API.

<<<<<<< HEAD
## Upgrade Guidelines

- `1.0.0-rc.1`
### 1.0.0-rc.0 to x

[#45](https://github.com/open-telemetry/opentelemetry-js-api/pull/45) `Span#context` renamed to `Span#spanContext`
- `HttpBaggage` renamed to `HttpBaggagePropagator`
- [#45](https://github.com/open-telemetry/opentelemetry-js-api/pull/45) `Span#context` renamed to `Span#spanContext`

## Useful links

Expand All @@ -94,12 +126,11 @@ Apache 2.0 - See [LICENSE][license-url] for more information.
[discussions-url]: https://github.com/open-telemetry/opentelemetry-js/discussions
[license-url]: https://github.com/open-telemetry/opentelemetry-js-api/blob/main/LICENSE
[license-image]: https://img.shields.io/badge/license-Apache_2.0-green.svg?style=flat
[dependencies-image]: https://david-dm.org/open-telemetry/opentelemetry-js-api/status.svg
[dependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js-api.svg
[dependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js-api
[devDependencies-image]: https://david-dm.org/open-telemetry/opentelemetry-js-api/dev-status.svg
[devDependencies-image]: https://status.david-dm.org/gh/open-telemetry/opentelemetry-js-api.svg?type=dev
[devDependencies-url]: https://david-dm.org/open-telemetry/opentelemetry-js-api?type=dev
[npm-url]: https://www.npmjs.com/package/@opentelemetry/api
[npm-img]: https://badge.fury.io/js/%40opentelemetry%2Fapi.svg

[docs-tracing]: https://github.com/open-telemetry/opentelemetry-js-api/blob/main/docs/tracing.md
[docs-sdk-registration]: https://github.com/open-telemetry/opentelemetry-js-api/blob/main/docs/sdk-registration.md
6 changes: 3 additions & 3 deletions src/context/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { Context } from './types';
import { Baggage, Span, SpanContext } from '../';
import { NoopSpan } from '../trace/NoopSpan';
import { NonRecordingSpan } from '../trace/NonRecordingSpan';

/**
* span key
Expand Down Expand Up @@ -56,7 +56,7 @@ export function setSpan(context: Context, span: Span): Context {
}

/**
* Wrap span context in a NoopSpan and set as span in a new
* Wrap span context in a NonRecordingSpan and set as span in a new
* context
*
* @param context context to set active span on
Expand All @@ -66,7 +66,7 @@ export function setSpanContext(
context: Context,
spanContext: SpanContext
): Context {
return setSpan(context, new NoopSpan(spanContext));
return setSpan(context, new NonRecordingSpan(spanContext));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/trace/NoopSpan.ts → src/trace/NonRecordingSpan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ import { SpanStatus } from './status';
import { INVALID_SPAN_CONTEXT } from './spancontext-utils';

/**
* The NoopSpan is the default {@link Span} that is used when no Span
* The NonRecordingSpan is the default {@link Span} that is used when no Span
* implementation is available. All operations are no-op including context
* propagation.
*/
export class NoopSpan implements Span {
export class NonRecordingSpan implements Span {
constructor(
private readonly _spanContext: SpanContext = INVALID_SPAN_CONTEXT
) {}
Expand Down Expand Up @@ -65,7 +65,7 @@ export class NoopSpan implements Span {
// By default does nothing
end(_endTime?: TimeInput): void {}

// isRecording always returns false for noopSpan.
// isRecording always returns false for NonRecordingSpan.
isRecording(): boolean {
return false;
}
Expand Down
8 changes: 4 additions & 4 deletions src/trace/NoopTracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { getSpanContext } from '../context/context';
import { Context } from '../context/types';
import { NoopSpan } from './NoopSpan';
import { NonRecordingSpan } from './NonRecordingSpan';
import { Span } from './span';
import { isSpanContextValid } from './spancontext-utils';
import { SpanOptions } from './SpanOptions';
Expand All @@ -31,7 +31,7 @@ export class NoopTracer implements Tracer {
startSpan(name: string, options?: SpanOptions, context?: Context): Span {
const root = Boolean(options?.root);
if (root) {
return new NoopSpan();
return new NonRecordingSpan();
}

const parentFromContext = context && getSpanContext(context);
Expand All @@ -40,9 +40,9 @@ export class NoopTracer implements Tracer {
isSpanContext(parentFromContext) &&
isSpanContextValid(parentFromContext)
) {
return new NoopSpan(parentFromContext);
return new NonRecordingSpan(parentFromContext);
} else {
return new NoopSpan();
return new NonRecordingSpan();
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions test/api/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import api, {
diag,
} from '../../src';
import { DiagAPI } from '../../src/api/diag';
import { NoopSpan } from '../../src/trace/NoopSpan';
import { NonRecordingSpan } from '../../src/trace/NonRecordingSpan';

// DiagLogger implementation
const diagLoggerFunctions = [
Expand Down Expand Up @@ -78,7 +78,7 @@ describe('API', () => {
spanId: '6e0c63257de34c92',
traceFlags: TraceFlags.NONE,
};
const dummySpan = new NoopSpan(spanContext);
const dummySpan = new NonRecordingSpan(spanContext);

beforeEach(() => {
context.disable();
Expand Down
6 changes: 3 additions & 3 deletions test/noop-implementations/noop-span.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import {
INVALID_TRACEID,
TraceFlags,
} from '../../src';
import { NoopSpan } from '../../src/trace/NoopSpan';
import { NonRecordingSpan } from '../../src/trace/NonRecordingSpan';

describe('NoopSpan', () => {
describe('NonRecordingSpan', () => {
it('do not crash', () => {
const span = new NoopSpan();
const span = new NonRecordingSpan();
span.setAttribute('my_string_attribute', 'foo');
span.setAttribute('my_number_attribute', 123);
span.setAttribute('my_boolean_attribute', false);
Expand Down
8 changes: 4 additions & 4 deletions test/noop-implementations/noop-tracer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ import {
context,
setSpanContext,
} from '../../src';
import { NoopSpan } from '../../src/trace/NoopSpan';
import { NonRecordingSpan } from '../../src/trace/NonRecordingSpan';

describe('NoopTracer', () => {
it('should not crash', () => {
const tracer = new NoopTracer();

assert.ok(tracer.startSpan('span-name') instanceof NoopSpan);
assert.ok(tracer.startSpan('span-name') instanceof NonRecordingSpan);
assert.ok(
tracer.startSpan('span-name1', { kind: SpanKind.CLIENT }) instanceof
NoopSpan
NonRecordingSpan
);
assert.ok(
tracer.startSpan('span-name2', { kind: SpanKind.CLIENT }) instanceof
NoopSpan
NonRecordingSpan
);
});

Expand Down
10 changes: 5 additions & 5 deletions test/proxy-implementations/proxy-tracer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
ROOT_CONTEXT,
SpanOptions,
} from '../../src';
import { NoopSpan } from '../../src/trace/NoopSpan';
import { NonRecordingSpan } from '../../src/trace/NonRecordingSpan';

describe('ProxyTracer', () => {
let provider: ProxyTracerProvider;
Expand All @@ -51,14 +51,14 @@ describe('ProxyTracer', () => {
it('startSpan should return Noop Spans', () => {
const tracer = provider.getTracer('test');

assert.ok(tracer.startSpan('span-name') instanceof NoopSpan);
assert.ok(tracer.startSpan('span-name') instanceof NonRecordingSpan);
assert.ok(
tracer.startSpan('span-name1', { kind: SpanKind.CLIENT }) instanceof
NoopSpan
NonRecordingSpan
);
assert.ok(
tracer.startSpan('span-name2', { kind: SpanKind.CLIENT }) instanceof
NoopSpan
NonRecordingSpan
);
});
});
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('ProxyTracer', () => {
let delegateTracer: Tracer;

beforeEach(() => {
delegateSpan = new NoopSpan();
delegateSpan = new NonRecordingSpan();
delegateTracer = {
startSpan() {
return delegateSpan;
Expand Down

0 comments on commit 9538416

Please sign in to comment.