Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(exporters): update proto version and use otlp-transformer #2929

Merged
merged 32 commits into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f6e2f5f
chore: updating submodule for otlp-grpc-exporter-base
pichlermarc Apr 25, 2022
a8f045d
chore: updating submodule for otlp-proto-exporter-base
pichlermarc Apr 25, 2022
606870a
feat(otlp-metrics-exporter): update to proto 0.14.
pichlermarc Apr 27, 2022
ca54530
feat(otlp-trace-exporter): update to proto 0.14.
pichlermarc Apr 26, 2022
c801f42
fix(changelog): update changelog.
pichlermarc Apr 27, 2022
258e503
feat(exporter-trace-otlp-http): use hex representation for traceId an…
pichlermarc Apr 27, 2022
aed89cb
feat(otlp-transformer): update tests for base64 trace and span id rep…
pichlermarc Apr 27, 2022
78720de
feat(protos): update protos to 0.16
pichlermarc Apr 27, 2022
48b14af
fix(exporter): cleanup dependencies.
pichlermarc Apr 27, 2022
90eaaab
fix(exporters): cleanup.
pichlermarc Apr 27, 2022
f04dcb5
fix(otlp-transformer): rename IInstrumentationLibrarySpans to IScopeS…
pichlermarc Apr 29, 2022
dbc1a35
feat(otlp-exporter-example): update example to use new exporter version.
pichlermarc Apr 29, 2022
69110d7
Merge branch 'main' into use-updated-proto
pichlermarc Apr 29, 2022
7052b25
docs(exporters): update readme files.
pichlermarc Apr 29, 2022
d32f440
fix(otlp-metric-exporter): map over metrics directly.
pichlermarc Apr 29, 2022
e591ad3
fix(exporter-trace-otlp-proto): rename constant instrumentationLibrar…
pichlermarc Apr 29, 2022
87be662
fix(otlp-exporter): use assert.ok() instead of assert.strictEqual() i…
pichlermarc Apr 29, 2022
4eae398
feat(otlp-transformer): add support for instrumentationLibarary next …
pichlermarc May 2, 2022
4507c52
fix(otlp-transformer): change publish config from 'restricted' to 'pu…
pichlermarc May 2, 2022
993e1a3
Merge remote-tracking branch 'upstream/main' into use-updated-proto
pichlermarc May 2, 2022
6c77da9
docs(readme): add upgrade guidelines entries.
pichlermarc May 2, 2022
f0c4fc5
fix(otlp-transformer): cleanup.
pichlermarc May 2, 2022
3cd3a0e
docs(otlp-exporters): add compatible version range for opentelemetry-…
pichlermarc May 2, 2022
d7f400e
docs(exporter-metrics-otlp-http): remove double newline.
pichlermarc May 2, 2022
fbcf9c3
feat(otlp-transformer): revert to only publishing scopeMetrics.
pichlermarc May 3, 2022
00e7015
docs(otlp-exporter-node-example): fix links.
pichlermarc May 3, 2022
c33fbe1
fix(otlp-exporters): cleanup test assertions.
pichlermarc May 3, 2022
02c4c55
fix(otlp-exporters): cleanup tests.
pichlermarc May 3, 2022
35d9762
fix(exporter-trace-otlp-http): remove 'if' for undefined checks.
pichlermarc May 4, 2022
47aa7e4
fix(otlp-exporters): remove 'if' for undefined checks from tests.
pichlermarc May 4, 2022
2dcb4c1
fix(otlp-exporters): remove more 'if's for undefined checks from tests.
pichlermarc May 4, 2022
052eabb
Merge branch 'main' into use-updated-proto
pichlermarc May 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,13 @@ These instrumentations are hosted at <https://github.com/open-telemetry/opentele

## Upgrade guidelines

### 0.28.x to 0.29.x

- `@opentelemetry/exporter-trace-otlp-http` is now exporting `scopeSpans` instead of `instrumentationLibrarySpans`
- this exporter now requires collector version `0.48` and up.
dyladan marked this conversation as resolved.
Show resolved Hide resolved
- `@opentelemetry/exporter-metrics-otlp-http` is now exporting `scopeMetrics` instead of `instrumentationLibraryMetrics`
- this exporter now requires collector version `0.48` and up.

### 0.27.x to 0.28.x

- In `@opentelemetry/exporter-trace-otlp-http`, `OTLPExporterBase._isShutdown` is replaced with `_shutdownOnce`.
Expand Down
9 changes: 4 additions & 5 deletions examples/otlp-exporter-node/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# Overview

<!-- TODO: This example needs an update. -->

This example shows how to use [@opentelemetry/exporter-otlp-http](https://github.com/open-telemetry/opentelemetry-js/tree/v0.26.0/experimental/packages/opentelemetry-exporter-otlp-http) to instrument a simple Node.js application.

This example will export spans data simultaneously using [Exporter Collector](https://github.com/open-telemetry/opentelemetry-js/tree/v0.26.0/experimental/packages/opentelemetry-exporter-otlp-http) and grpc. It will use [proto format](https://github.com/open-telemetry/opentelemetry-proto).
This example shows how to use
[@opentelemetry/exporter-trace-otlp-http](https://github.com/open-telemetry/opentelemetry-js/tree/v0.26.0/experimental/packages/opentelemetry-exporter-trace-otlp-http)
and [@opentelemetry/exporter-metrics-otlp-http](https://github.com/open-telemetry/opentelemetry-js/tree/v0.26.0/experimental/packages/opentelemetry-exporter-metrics-otlp-http)
blumamir marked this conversation as resolved.
Show resolved Hide resolved
to instrument a simple Node.js application.

## Installation

Expand Down
2 changes: 1 addition & 1 deletion examples/otlp-exporter-node/docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: "3"
services:
# Collector
collector:
image: otel/opentelemetry-collector-contrib:0.42.0
image: otel/opentelemetry-collector-contrib:0.50.0
# image: otel/opentelemetry-collector-contrib:latest
command: ["--config=/conf/collector-config.yaml"]
volumes:
Expand Down
31 changes: 17 additions & 14 deletions examples/otlp-exporter-node/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,29 @@

const { DiagConsoleLogger, DiagLogLevel, diag } = require('@opentelemetry/api');
const { OTLPMetricExporter } = require('@opentelemetry/exporter-metrics-otlp-http');
// const { OTLPMetricExporter } = require('@opentelemetry/exporter-otlp-grpc');
// const { OTLPMetricExporter } = require('@opentelemetry/exporter-otlp-proto');
const { MeterProvider } = require('@opentelemetry/sdk-metrics-base');
// const { OTLPMetricExporter } = require('@opentelemetry/exporter-metrics-otlp-grpc');
// const { OTLPMetricExporter } = require('@opentelemetry/exporter-metrics-otlp-proto');
const { MeterProvider, PeriodicExportingMetricReader } = require('@opentelemetry/sdk-metrics-base');
const { Resource } = require('@opentelemetry/resources');
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');

// Optional and only needed to see the internal diagnostic logging (during development)
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);

const metricExporter = new OTLPMetricExporter({
url: 'http://localhost:4318/v1/metrics',
});
const metricExporter = new OTLPMetricExporter({});

const meter = new MeterProvider({
exporter: metricExporter,
interval: 1000,
const meterProvider = new MeterProvider({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'basic-metric-service',
}),
}).getMeter('example-exporter-collector');
});

meterProvider.addMetricReader(new PeriodicExportingMetricReader({
exporter: metricExporter,
exportIntervalMillis: 1000,
}));

const meter = meterProvider.getMeter('example-exporter-collector');

const requestCounter = meter.createCounter('requests', {
description: 'Example of a Counter',
Expand All @@ -35,10 +38,10 @@ const histogram = meter.createHistogram('test_histogram', {
description: 'Example of a Histogram',
});

const labels = { pid: process.pid, environment: 'staging' };
const attributes = { pid: process.pid, environment: 'staging' };

setInterval(() => {
requestCounter.add(1, labels);
upDownCounter.add(Math.random() > 0.5 ? 1 : -1, labels);
histogram.record(Math.random(), labels);
requestCounter.add(1, attributes);
upDownCounter.add(Math.random() > 0.5 ? 1 : -1, attributes);
histogram.record(Math.random(), attributes);
}, 1000);
23 changes: 12 additions & 11 deletions examples/otlp-exporter-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,18 @@
},
"dependencies": {
"@opentelemetry/api": "^1.0.2",
"@opentelemetry/core": "1.0.1",
"@opentelemetry/exporter-trace-otlp-http": "0.27.0",
"@opentelemetry/exporter-metrics-otlp-http": "0.27.0",
"@opentelemetry/exporter-trace-otlp-grpc": "0.27.0",
"@opentelemetry/exporter-metrics-otlp-grpc": "0.27.0",
"@opentelemetry/exporter-trace-otlp-proto": "0.27.0",
"@opentelemetry/exporter-metrics-otlp-proto": "0.27.0",
"@opentelemetry/resources": "1.0.1",
"@opentelemetry/semantic-conventions": "1.0.1",
"@opentelemetry/sdk-metrics-base": "0.27.0",
"@opentelemetry/sdk-trace-base": "1.0.1"
"@opentelemetry/api-metrics": "0.28.0",
"@opentelemetry/core": "1.1.1",
"@opentelemetry/exporter-trace-otlp-http": "0.28.0",
"@opentelemetry/exporter-metrics-otlp-http": "0.28.0",
"@opentelemetry/exporter-trace-otlp-grpc": "0.28.0",
"@opentelemetry/exporter-metrics-otlp-grpc": "0.28.0",
"@opentelemetry/exporter-trace-otlp-proto": "0.28.0",
"@opentelemetry/exporter-metrics-otlp-proto": "0.28.0",
"@opentelemetry/resources": "1.1.1",
"@opentelemetry/semantic-conventions": "1.1.1",
"@opentelemetry/sdk-metrics-base": "0.28.0",
"@opentelemetry/sdk-trace-base": "1.1.1"
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js#readme"
}
23 changes: 13 additions & 10 deletions examples/otlp-exporter-node/tracing.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
'use strict';

const opentelemetry = require('@opentelemetry/api');
const { BasicTracerProvider, ConsoleSpanExporter, SimpleSpanProcessor } = require('@opentelemetry/sdk-trace-base');
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http');
const { Resource } = require('@opentelemetry/resources');
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
// const { OTLPTraceExporter } = require('@opentelemetry/exporter-otlp-grpc');
// const { OTLPTraceExporter } = require('@opentelemetry/exporter-otlp-proto');
const {
diag,
trace,
context,
DiagConsoleLogger,
DiagLogLevel,
} = require('@opentelemetry/api');
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http');
// const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-grpc');
// const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-proto');

// opentelemetry.diag.setLogger(
// new opentelemetry.DiagConsoleLogger(),
// opentelemetry.DiagLogLevel.DEBUG,
// );
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);

const exporter = new OTLPTraceExporter({
// headers: {
Expand All @@ -28,7 +31,7 @@ provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
provider.register();

const tracer = opentelemetry.trace.getTracer('example-otlp-exporter-node');
const tracer = trace.getTracer('example-otlp-exporter-node');

// Create a span. A span must be closed.
const parentSpan = tracer.startSpan('main');
Expand All @@ -47,7 +50,7 @@ setTimeout(() => {
function doWork(parent) {
// Start another span. In this example, the main method already started a
// span, so that'll be the parent span, and this will be a child span.
const ctx = opentelemetry.trace.setSpan(opentelemetry.context.active(), parent);
const ctx = trace.setSpan(context.active(), parent);
const span = tracer.startSpan('doWork', undefined, ctx);

// simulate some random work.
Expand Down
2 changes: 2 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ All notable changes to experimental packages in this project will be documented

### :rocket: (Enhancement)

* feat(exporters): update proto version and use otlp-transformer #2929 @pichlermarc

### :bug: (Bug Fix)

### :books: (Refine Doc)
Expand Down
8 changes: 4 additions & 4 deletions experimental/packages/exporter-trace-otlp-grpc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
[![NPM Published Version][npm-img]][npm-url]
[![Apache License][license-image]][license-image]

This module provides exporter for web and node to be used with [opentelemetry-collector][opentelemetry-collector-url] - last tested with version **0.25.0**.
This module provides exporter for web and node to be used with [opentelemetry-collector][opentelemetry-collector-url].
Compatible with [opentelemetry-collector][opentelemetry-collector-url] versions `>=0.16 <=0.50`.

## Installation

Expand Down Expand Up @@ -135,9 +136,8 @@ OTEL_EXPORTER_OTLP_TRACES_COMPRESSION=gzip

## Running opentelemetry-collector locally to see the traces

1. Go to examples/otlp-exporter-node
2. run `npm run docker:start`
3. Open page at `http://localhost:9411/zipkin/` to observe the traces
1. Go to `examples/otlp-exporter-node`
2. Follow the instructions there to inspect traces.

## Useful links

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"@opentelemetry/core": "1.2.0",
"@grpc/grpc-js": "^1.5.9",
"@grpc/proto-loader": "^0.6.9",
"@opentelemetry/exporter-trace-otlp-http": "0.28.0",
"@opentelemetry/otlp-transformer": "0.28.0",
"@opentelemetry/otlp-grpc-exporter-base": "0.28.0",
"@opentelemetry/resources": "1.2.0",
"@opentelemetry/sdk-trace-base": "1.2.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
*/

import { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';
import {
otlpTypes,
toOTLPExportTraceServiceRequest,
} from '@opentelemetry/exporter-trace-otlp-http';
import { baggageUtils, getEnv } from '@opentelemetry/core';
import { Metadata } from '@grpc/grpc-js';
import {
Expand All @@ -27,6 +23,7 @@ import {
ServiceClientType,
validateAndNormalizeUrl
} from '@opentelemetry/otlp-grpc-exporter-base';
import { createExportTraceServiceRequest, IExportTraceServiceRequest } from '@opentelemetry/otlp-transformer';

const DEFAULT_COLLECTOR_URL = 'localhost:4317';

Expand All @@ -35,7 +32,7 @@ const DEFAULT_COLLECTOR_URL = 'localhost:4317';
*/
export class OTLPTraceExporter
extends OTLPGRPCExporterNodeBase<ReadableSpan,
otlpTypes.opentelemetryProto.collector.trace.v1.ExportTraceServiceRequest>
IExportTraceServiceRequest>
implements SpanExporter {

constructor(config: OTLPGRPCExporterConfigNode = {}) {
Expand All @@ -47,10 +44,8 @@ export class OTLPTraceExporter
}
}

convert(
spans: ReadableSpan[]
): otlpTypes.opentelemetryProto.collector.trace.v1.ExportTraceServiceRequest {
return toOTLPExportTraceServiceRequest(spans, this);
convert(spans: ReadableSpan[]): IExportTraceServiceRequest {
return createExportTraceServiceRequest(spans);
}

getDefaultUrl(config: OTLPGRPCExporterConfigNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

import * as protoLoader from '@grpc/proto-loader';
import { otlpTypes } from '@opentelemetry/exporter-trace-otlp-http';
import { diag } from '@opentelemetry/api';
import {
BasicTracerProvider,
Expand All @@ -37,6 +36,7 @@ import {
} from './traceHelper';
import { CompressionAlgorithm } from '@opentelemetry/otlp-exporter-base';
import { GrpcCompressionAlgorithm } from '@opentelemetry/otlp-grpc-exporter-base';
import { IExportTraceServiceRequest, IResourceSpans } from '@opentelemetry/otlp-transformer';

const traceServiceProtoPath =
'opentelemetry/proto/collector/trace/v1/trace_service.proto';
Expand All @@ -59,7 +59,7 @@ const testCollectorExporter = (params: TestParams) =>
let collectorExporter: OTLPTraceExporter;
let server: grpc.Server;
let exportedData:
| otlpTypes.opentelemetryProto.trace.v1.ResourceSpans
| IResourceSpans
| undefined;
let reqMetadata: grpc.Metadata | undefined;

Expand All @@ -83,15 +83,13 @@ const testCollectorExporter = (params: TestParams) =>
.service,
{
Export: (data: {
request: otlpTypes.opentelemetryProto.collector.trace.v1.ExportTraceServiceRequest;
request: IExportTraceServiceRequest;
metadata: grpc.Metadata;
}) => {
try {
if (data.request.resourceSpans != null) {
exportedData = data.request.resourceSpans[0];
reqMetadata = data.metadata;
} catch (e) {
exportedData = undefined;
}
reqMetadata = data.metadata;
},
}
);
Expand Down Expand Up @@ -181,9 +179,16 @@ const testCollectorExporter = (params: TestParams) =>
let spans;
let resource;
if (exportedData) {
spans = exportedData.instrumentationLibrarySpans[0].spans;
spans = exportedData.scopeSpans[0].spans;
resource = exportedData.resource;
ensureExportedSpanIsCorrect(spans[0]);

assert.ok(
typeof spans !== 'undefined',
'spans do not exist'
);
if(spans) {
ensureExportedSpanIsCorrect(spans[0]);
legendecas marked this conversation as resolved.
Show resolved Hide resolved
}

assert.ok(
typeof resource !== 'undefined',
Expand Down Expand Up @@ -231,8 +236,13 @@ const testCollectorExporter = (params: TestParams) =>
let spans;
let resource;
if (exportedData) {
spans = exportedData.instrumentationLibrarySpans[0].spans;
spans = exportedData.scopeSpans[0].spans;
resource = exportedData.resource;

assert.ok(
typeof spans !== 'undefined',
'spans do not exist'
);
ensureExportedSpanIsCorrect(spans[0]);

assert.ok(
Expand Down Expand Up @@ -261,7 +271,7 @@ const testCollectorExporter = (params: TestParams) =>
)
: undefined;

envSource.OTEL_EXPORTER_OTLP_COMPRESSION='gzip';
envSource.OTEL_EXPORTER_OTLP_COMPRESSION = 'gzip';
collectorExporter = new OTLPTraceExporter({
url: 'grpcs://' + address,
credentials,
Expand Down Expand Up @@ -334,8 +344,8 @@ describe('when configuring via environment', () => {
});
});

testCollectorExporter({ useTLS: true });
testCollectorExporter({ useTLS: false });
testCollectorExporter({ metadata });


describe('', () => {
legendecas marked this conversation as resolved.
Show resolved Hide resolved
testCollectorExporter({ useTLS: true });
testCollectorExporter({ useTLS: false });
testCollectorExporter({ metadata });
});
Loading