Skip to content

Commit

Permalink
Merge branch 'main' into propagators
Browse files Browse the repository at this point in the history
  • Loading branch information
obecny authored Apr 28, 2021
2 parents ffff74c + c4341c3 commit eeab680
Show file tree
Hide file tree
Showing 31 changed files with 367 additions and 176 deletions.
12 changes: 6 additions & 6 deletions examples/grpc-js/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ const EXPORTER = process.env.EXPORTER || '';

module.exports = (serviceName) => {
const provider = new NodeTracerProvider();
registerInstrumentations({
instrumentations: [
new GrpcInstrumentation(),
],
tracerProvider: provider,
});

let exporter;
if (EXPORTER.toLowerCase().startsWith('z')) {
Expand All @@ -35,5 +29,11 @@ module.exports = (serviceName) => {
// Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings
provider.register();

registerInstrumentations({
instrumentations: [
new GrpcInstrumentation(),
],
});

return opentelemetry.trace.getTracer('grpc-js-example');
};
12 changes: 6 additions & 6 deletions examples/grpc/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ const EXPORTER = process.env.EXPORTER || '';

module.exports = (serviceName) => {
const provider = new NodeTracerProvider();
registerInstrumentations({
tracerProvider: provider,
instrumentations: [
new GrpcInstrumentation(),
],
});

let exporter;
if (EXPORTER.toLowerCase().startsWith('z')) {
Expand All @@ -35,5 +29,11 @@ module.exports = (serviceName) => {
// Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings
provider.register();

registerInstrumentations({
instrumentations: [
new GrpcInstrumentation(),
],
});

return opentelemetry.trace.getTracer('grpc-example');
};
14 changes: 7 additions & 7 deletions examples/http/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ const EXPORTER = process.env.EXPORTER || '';

module.exports = (serviceName) => {
const provider = new NodeTracerProvider();
registerInstrumentations({
tracerProvider: provider,
// // when boostraping with lerna for testing purposes
instrumentations: [
new HttpInstrumentation(),
],
});

let exporter;
if (EXPORTER.toLowerCase().startsWith('z')) {
Expand All @@ -36,5 +29,12 @@ module.exports = (serviceName) => {
// Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings
provider.register();

registerInstrumentations({
// // when boostraping with lerna for testing purposes
instrumentations: [
new HttpInstrumentation(),
],
});

return opentelemetry.trace.getTracer('http-example');
};
12 changes: 6 additions & 6 deletions examples/https/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
module.exports = (serviceName) => {
let exporter;
const provider = new NodeTracerProvider();
registerInstrumentations({
tracerProvider: provider,
instrumentations: [
new HttpInstrumentation(),
],
});

if (EXPORTER.toLowerCase().startsWith('z')) {
exporter = new ZipkinExporter({
Expand All @@ -36,5 +30,11 @@ module.exports = (serviceName) => {
// Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings
provider.register();

registerInstrumentations({
instrumentations: [
new HttpInstrumentation(),
],
});

return opentelemetry.trace.getTracer('https-example');
};
6 changes: 3 additions & 3 deletions examples/opentracing-shim/shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ const { TracerShim } = require('@opentelemetry/shim-opentracing');

function shim(serviceName) {
const provider = new NodeTracerProvider();
registerInstrumentations({
tracerProvider: provider,
});

provider.addSpanProcessor(new SimpleSpanProcessor(getExporter(serviceName)));
// Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings
provider.register();

registerInstrumentations({
});

return new TracerShim(provider.getTracer('opentracing-shim'));
}

Expand Down
16 changes: 7 additions & 9 deletions examples/tracer-web/examples/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import { B3Propagator } from '@opentelemetry/propagator-b3';
import { registerInstrumentations } from '@opentelemetry/instrumentation';

const provider = new WebTracerProvider();
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
provider.addSpanProcessor(new SimpleSpanProcessor(new CollectorTraceExporter()));
provider.register({
contextManager: new ZoneContextManager(),
propagator: new B3Propagator(),
});

registerInstrumentations({
instrumentations: [
Expand All @@ -20,17 +26,9 @@ registerInstrumentations({
'https://cors-test.appspot.com/test',
'https://httpbin.org/get',
],
clearTimingResources: true
clearTimingResources: true,
}),
],
tracerProvider: provider,
});

provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
provider.addSpanProcessor(new SimpleSpanProcessor(new CollectorTraceExporter()));
provider.register({
contextManager: new ZoneContextManager(),
propagator: new B3Propagator(),
});

const webTracerWithZone = provider.getTracer('example-tracer-web');
Expand Down
16 changes: 7 additions & 9 deletions examples/tracer-web/examples/xml-http-request/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import { B3Propagator } from '@opentelemetry/propagator-b3';
import { registerInstrumentations } from '@opentelemetry/instrumentation';

const providerWithZone = new WebTracerProvider();
providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new CollectorTraceExporter()));

providerWithZone.register({
contextManager: new ZoneContextManager(),
propagator: new B3Propagator(),
});

registerInstrumentations({
instrumentations: [
Expand All @@ -18,15 +25,6 @@ registerInstrumentations({
],
}),
],
tracerProvider: providerWithZone,
});

providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
providerWithZone.addSpanProcessor(new SimpleSpanProcessor(new CollectorTraceExporter()));

providerWithZone.register({
contextManager: new ZoneContextManager(),
propagator: new B3Propagator(),
});

const webTracerWithZone = providerWithZone.getTracer('example-tracer-web');
Expand Down
6 changes: 2 additions & 4 deletions getting-started/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ This guide walks you through the setup and configuration process for a tracing b

- [Getting started with OpenTelemetry JS](#getting-started-with-opentelemetry-js)
- [Trace your application with OpenTelemetry](#trace-your-application-with-opentelemetry)
- [Set up a Tracing Backend](#set-up-a-tracing-backend)
- [Trace Your NodeJS Application](#trace-your-nodejs-application)
- [Set up a tracing backend](#set-up-a-tracing-backend)
- [Trace your NodeJS application](#trace-your-nodejs-application)
- [Install the required OpenTelemetry libraries](#install-the-required-opentelemetry-libraries)
- [Initialize a global tracer](#initialize-a-global-tracer)
- [Initialize and register a trace exporter](#initialize-and-register-a-trace-exporter)
Expand Down Expand Up @@ -92,7 +92,6 @@ registerInstrumentations({
new HttpInstrumentation(),
new GrpcInstrumentation(),
],
tracerProvider: provider,
});

```
Expand Down Expand Up @@ -153,7 +152,6 @@ registerInstrumentations({
new HttpInstrumentation(),
new GrpcInstrumentation(),
],
tracerProvider: provider,
});

console.log("tracing initialized");
Expand Down
1 change: 0 additions & 1 deletion getting-started/traced-example/tracing.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ provider.register();

// load old default plugins
registerInstrumentations({
tracerProvider: provider,
instrumentations: [
new ExpressInstrumentation(),
new HttpInstrumentation(),
Expand Down
6 changes: 2 additions & 4 deletions getting-started/ts-example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ const provider: NodeTracerProvider = new NodeTracerProvider({
provider.register();

registerInstrumentations({
tracerProvider: provider,
instrumentations: [
new ExpressInstrumentation(),
new HttpInstrumentation(),
Expand Down Expand Up @@ -137,8 +136,6 @@ const provider: NodeTracerProvider = new NodeTracerProvider({
logLevel: LogLevel.ERROR,
});

provider.register();

provider.addSpanProcessor(
new SimpleSpanProcessor(
new ZipkinExporter({
Expand All @@ -152,8 +149,9 @@ provider.addSpanProcessor(
),
);

provider.register();

registerInstrumentations({
tracerProvider: provider,
instrumentations: [
new ExpressInstrumentation(),
new HttpInstrumentation(),
Expand Down
5 changes: 1 addition & 4 deletions getting-started/ts-example/traced-example/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ const { ExpressInstrumentation } = require('@opentelemetry/instrumentation-expre
const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http');

const provider: NodeTracerProvider = new NodeTracerProvider();

provider.register();

provider.addSpanProcessor(
new SimpleSpanProcessor(
new ZipkinExporter({
Expand All @@ -25,9 +22,9 @@ provider.addSpanProcessor(
}),
),
);
provider.register();

registerInstrumentations({
tracerProvider: provider,
instrumentations: [
new ExpressInstrumentation(),
new HttpInstrumentation(),
Expand Down
12 changes: 12 additions & 0 deletions packages/opentelemetry-api-metrics/src/types/Metric.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ export interface MetricOptions {
* Boundaries optional for histogram
*/
boundaries?: number[];

/**
* Aggregation Temporality of metric
*/
aggregationTemporality?: AggregationTemporality;
}

export interface BatchObserverOptions {
Expand All @@ -73,6 +78,13 @@ export enum ValueType {
DOUBLE,
}

/** The kind of aggregator. */
export enum AggregationTemporality {
AGGREGATION_TEMPORALITY_UNSPECIFIED,
AGGREGATION_TEMPORALITY_DELTA,
AGGREGATION_TEMPORALITY_CUMULATIVE,
}

/**
* Metric represents a base class for different types of metric
* pre aggregations.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
SpanAttributes,
Context,
getSpanContext,
isSpanContextValid,
Link,
Sampler,
SamplingResult,
Expand Down Expand Up @@ -69,7 +70,7 @@ export class ParentBasedSampler implements Sampler {
): SamplingResult {
const parentContext = getSpanContext(context);

if (!parentContext) {
if (!parentContext || !isSpanContextValid(parentContext)) {
return this._root.shouldSample(
context,
traceId,
Expand Down
36 changes: 36 additions & 0 deletions packages/opentelemetry-core/test/trace/ParentBasedSampler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,24 @@ describe('ParentBasedSampler', () => {
);
});

it('should return api.SamplingDecision.RECORD_AND_SAMPLED for invalid parent spanContext while composited with AlwaysOnSampler', () => {
const sampler = new ParentBasedSampler({ root: new AlwaysOnSampler() });

assert.deepStrictEqual(
sampler.shouldSample(
setSpanContext(api.ROOT_CONTEXT, api.INVALID_SPAN_CONTEXT),
traceId,
spanName,
SpanKind.CLIENT,
{},
[]
),
{
decision: api.SamplingDecision.RECORD_AND_SAMPLED,
}
);
});

it('should return api.SamplingDecision.RECORD_AND_SAMPLED while composited with AlwaysOnSampler', () => {
const sampler = new ParentBasedSampler({ root: new AlwaysOnSampler() });

Expand Down Expand Up @@ -112,6 +130,24 @@ describe('ParentBasedSampler', () => {
);
});

it('should return api.SamplingDecision.NOT_RECORD for invalid parent spanContext while composited with AlwaysOffSampler', () => {
const sampler = new ParentBasedSampler({ root: new AlwaysOffSampler() });

assert.deepStrictEqual(
sampler.shouldSample(
setSpanContext(api.ROOT_CONTEXT, api.INVALID_SPAN_CONTEXT),
traceId,
spanName,
SpanKind.CLIENT,
{},
[]
),
{
decision: api.SamplingDecision.NOT_RECORD,
}
);
});

it('should return api.SamplingDecision.RECORD_AND_SAMPLED while composited with AlwaysOffSampler', () => {
const sampler = new ParentBasedSampler({ root: new AlwaysOffSampler() });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ export function ensureExportedCounterIsCorrect(
},
],
isMonotonic: true,
aggregationTemporality: 'AGGREGATION_TEMPORALITY_DELTA',
aggregationTemporality: 'AGGREGATION_TEMPORALITY_CUMULATIVE',
},
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ export function ensureExportedCounterIsCorrect(
},
],
isMonotonic: true,
aggregationTemporality: 'AGGREGATION_TEMPORALITY_DELTA',
aggregationTemporality: 'AGGREGATION_TEMPORALITY_CUMULATIVE',
},
});
}
Expand Down
Loading

0 comments on commit eeab680

Please sign in to comment.