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

chore: updated exporter sample app to use new exporters #2577

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
32d7962
chore: updating submodule for opentelemetry-proto
Sep 21, 2021
f9972c8
chore: initialized exporter-metrics-otlp-grpc package
Sep 21, 2021
9685772
feat\!: populated exporter-metrics-otlp-grpc package
Sep 21, 2021
007970c
chore: bootstrapped exporter-metrics-otlp-http package
Sep 21, 2021
9618274
feat\!: migrated metric exporter logic to exporter-metrics-otlp-http
Sep 21, 2021
d2ecae0
chore: updating submodule for opentelemetry-proto
Sep 21, 2021
07b43bf
chore: bootstrapped exporter-metrics-otlp-proto package
Sep 21, 2021
5ac7d7b
feat!: migrated proto logic to exporter-metrics-otlp-proto package
Sep 21, 2021
308cfe3
fix: fixed some issues in grpc and proto
Sep 22, 2021
16e7a95
removed debug logging
Sep 22, 2021
c50cada
added api to devdeps
Sep 22, 2021
e5ed763
merge branch 'main' into split-exporters
Sep 29, 2021
0751815
fixed imports
Sep 29, 2021
b886cb9
merge 'main' into split-exporters
Oct 5, 2021
211fa12
updated versions to latest
Oct 5, 2021
9140258
fixed merge conflicts
Oct 26, 2021
8b3571f
applied changes from #2496 to metricHelpers
Oct 26, 2021
752463e
renamed exporter-otlp-http -> exporter-trace-otlp-http
Oct 26, 2021
c4aa74a
renamed exporter-otlp-grpc -> exporter-trace-otlp-grpc
Oct 26, 2021
3e7daf4
renamed exporter-otlp-proto -> exporter-trace-otlp-proto
Oct 26, 2021
44de3a7
Merge branch 'main' into split-exporters
dyladan Oct 26, 2021
8eccf90
Merge branch 'main' into split-exporters
vmarchaud Oct 27, 2021
2992e5c
fix conflicts and bump api version
Oct 28, 2021
81891ec
Merge branch 'split-exporters' of https://github.com/willarmiros/open…
Oct 28, 2021
59f33b4
chore: updated exporter sample app to use new exporters
Oct 31, 2021
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
Prev Previous commit
Next Next commit
fixed imports
  • Loading branch information
William Armiros committed Sep 29, 2021
commit 07518152ae7d2cae62bb83504cff1386ebd1aa04
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
import * as assert from 'assert';
import * as sinon from 'sinon';
import { OTLPMetricExporter } from '../../src/platform/browser/index';
import { otlpTypes } from '../../../../../packages/opentelemetry-exporter-otlp-http';
import { otlpTypes } from '@opentelemetry/exporter-otlp-http';
import {
ensureCounterIsCorrect,
ensureExportMetricsServiceRequestIsSet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
} from '@opentelemetry/sdk-metrics-base';
import * as assert from 'assert';
import * as sinon from 'sinon';
import { OTLPExporterBase, otlpTypes } from '../../../../../packages/opentelemetry-exporter-otlp-http';
import { OTLPExporterBase, otlpTypes } from '@opentelemetry/exporter-otlp-http';
import { mockCounter, mockObserver } from '../metricsHelper';

type CollectorExporterConfig = otlpTypes.OTLPExporterConfigBase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { InstrumentationLibrary, VERSION } from '@opentelemetry/core';
import * as metrics from '@opentelemetry/sdk-metrics-base';
import { Resource } from '@opentelemetry/resources';
import * as assert from 'assert';
import { otlpTypes } from '../../../../packages/opentelemetry-exporter-otlp-http';
import { otlpTypes } from '@opentelemetry/exporter-otlp-http';

const meterProvider = new metrics.MeterProvider({
interval: 30000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import * as sinon from 'sinon';
import {
OTLPMetricExporter,
} from '../../src/platform/node';
import { OTLPExporterNodeConfigBase, otlpTypes } from '../../../../../packages/opentelemetry-exporter-otlp-http';
import { OTLPExporterNodeConfigBase, otlpTypes } from '@opentelemetry/exporter-otlp-http';
import {
ensureCounterIsCorrect,
ensureExportMetricsServiceRequestIsSet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,45 @@
*/

import { SpanStatusCode, TraceFlags } from '@opentelemetry/api';
import { hexToBase64 } from '@opentelemetry/core';
import { otlpTypes } from '@opentelemetry/exporter-otlp-http';
import { Resource } from '@opentelemetry/resources';
import { ReadableSpan } from '@opentelemetry/sdk-trace-base';
import * as assert from 'assert';
import { Stream } from 'stream';
import * as grpc from '@grpc/grpc-js';
import { VERSION } from '@opentelemetry/core';

const traceIdHex = '1f1008dc8e270e85c40a0d7c3939b278';
const spanIdHex = '5e107261f64fa53e';
const parentIdHex = '78a8915098864388';
const traceIdArr = [
31,
16,
8,
220,
142,
39,
14,
133,
196,
10,
13,
124,
57,
57,
178,
120,
];
const spanIdArr = [94, 16, 114, 97, 246, 79, 165, 62];
const parentIdArr = [120, 168, 145, 80, 152, 134, 67, 136];

export const mockedReadableSpan: ReadableSpan = {
name: 'documentFetch',
kind: 0,
spanContext: () => {
return {
traceId: traceIdHex,
spanId: spanIdHex,
traceId: '1f1008dc8e270e85c40a0d7c3939b278',
spanId: '5e107261f64fa53e',
traceFlags: TraceFlags.SAMPLED,
};
},
parentSpanId: parentIdHex,
parentSpanId: '78a8915098864388',
startTime: [1574120165, 429803070],
endTime: [1574120165, 438688070],
ended: true,
Expand All @@ -45,8 +62,8 @@ export const mockedReadableSpan: ReadableSpan = {
links: [
{
context: {
traceId: traceIdHex,
spanId: parentIdHex,
traceId: '1f1008dc8e270e85c40a0d7c3939b278',
spanId: '78a8915098864388',
traceFlags: TraceFlags.SAMPLED,
},
attributes: { component: 'document-load' },
Expand Down Expand Up @@ -75,66 +92,74 @@ export const mockedReadableSpan: ReadableSpan = {
},
],
duration: [0, 8885000],
resource: new Resource({
resource: Resource.default().merge(new Resource({
service: 'ui',
version: 1,
cost: 112.12,
}),
})),
instrumentationLibrary: { name: 'default', version: '0.0.1' },
};

export function ensureProtoEventsAreCorrect(
export function ensureExportedEventsAreCorrect(
events: otlpTypes.opentelemetryProto.trace.v1.Span.Event[]
) {
assert.deepStrictEqual(
events,
[
{
attributes: [],
timeUnixNano: '1574120165429803008',
name: 'fetchStart',
droppedAttributesCount: 0,
},
{
attributes: [],
timeUnixNano: '1574120165429803008',
name: 'domainLookupStart',
droppedAttributesCount: 0,
},
{
attributes: [],
timeUnixNano: '1574120165429803008',
name: 'domainLookupEnd',
droppedAttributesCount: 0,
},
{
attributes: [],
timeUnixNano: '1574120165429803008',
name: 'connectStart',
droppedAttributesCount: 0,
},
{
attributes: [],
timeUnixNano: '1574120165429803008',
name: 'connectEnd',
droppedAttributesCount: 0,
},
{
attributes: [],
timeUnixNano: '1574120165435513088',
name: 'requestStart',
droppedAttributesCount: 0,
},
{
attributes: [],
timeUnixNano: '1574120165436923136',
name: 'responseStart',
droppedAttributesCount: 0,
},
{
attributes: [],
timeUnixNano: '1574120165438688000',
name: 'responseEnd',
droppedAttributesCount: 0,
},
],
'events are incorrect'
'exported events are incorrect'
);
}

export function ensureProtoAttributesAreCorrect(
export function ensureExportedAttributesAreCorrect(
attributes: otlpTypes.opentelemetryProto.common.v1.KeyValue[]
) {
assert.deepStrictEqual(
Expand All @@ -144,62 +169,66 @@ export function ensureProtoAttributesAreCorrect(
key: 'component',
value: {
stringValue: 'document-load',
value: 'stringValue',
},
},
],
'attributes are incorrect'
'exported attributes are incorrect'
);
}

export function ensureProtoLinksAreCorrect(
export function ensureExportedLinksAreCorrect(
attributes: otlpTypes.opentelemetryProto.trace.v1.Span.Link[]
) {
assert.deepStrictEqual(
attributes,
[
{
traceId: hexToBase64(traceIdHex),
spanId: hexToBase64(parentIdHex),
attributes: [
{
key: 'component',
value: {
stringValue: 'document-load',
value: 'stringValue',
},
},
],
traceId: Buffer.from(traceIdArr),
spanId: Buffer.from(parentIdArr),
traceState: '',
droppedAttributesCount: 0,
},
],
'links are incorrect'
'exported links are incorrect'
);
}

export function ensureProtoSpanIsCorrect(
export function ensureExportedSpanIsCorrect(
span: otlpTypes.opentelemetryProto.trace.v1.Span
) {
if (span.attributes) {
ensureProtoAttributesAreCorrect(span.attributes);
ensureExportedAttributesAreCorrect(span.attributes);
}
if (span.events) {
ensureProtoEventsAreCorrect(span.events);
ensureExportedEventsAreCorrect(span.events);
}
if (span.links) {
ensureProtoLinksAreCorrect(span.links);
ensureExportedLinksAreCorrect(span.links);
}
assert.deepStrictEqual(
span.traceId,
hexToBase64(traceIdHex),
'traceId is' + ' wrong'
Buffer.from(traceIdArr),
'traceId is wrong'
);
assert.deepStrictEqual(
span.spanId,
hexToBase64(spanIdHex),
'spanId is' + ' wrong'
Buffer.from(spanIdArr),
'spanId is wrong'
);
assert.strictEqual(span.traceState, '', 'traceState is wrong');
assert.deepStrictEqual(
span.parentSpanId,
hexToBase64(parentIdHex),
Buffer.from(parentIdArr),
'parentIdArr is wrong'
);
assert.strictEqual(span.name, 'documentFetch', 'name is wrong');
Expand All @@ -223,59 +252,80 @@ export function ensureProtoSpanIsCorrect(
assert.strictEqual(span.droppedLinksCount, 0, 'droppedLinksCount is wrong');
assert.deepStrictEqual(
span.status,
{ code: 'STATUS_CODE_OK' },
{
code: 'STATUS_CODE_OK',
deprecatedCode: 'DEPRECATED_STATUS_CODE_OK',
message: '',
},
'status is wrong'
);
}

export function ensureExportTraceServiceRequestIsSet(
json: otlpTypes.opentelemetryProto.collector.trace.v1.ExportTraceServiceRequest
export function ensureResourceIsCorrect(
resource: otlpTypes.opentelemetryProto.resource.v1.Resource
) {
const resourceSpans = json.resourceSpans;
assert.strictEqual(
resourceSpans && resourceSpans.length,
1,
'resourceSpans is missing'
);

const resource = resourceSpans[0].resource;
assert.strictEqual(!!resource, true, 'resource is missing');

const instrumentationLibrarySpans =
resourceSpans[0].instrumentationLibrarySpans;
assert.strictEqual(
instrumentationLibrarySpans && instrumentationLibrarySpans.length,
1,
'instrumentationLibrarySpans is missing'
);

const instrumentationLibrary =
instrumentationLibrarySpans[0].instrumentationLibrary;
assert.strictEqual(
!!instrumentationLibrary,
true,
'instrumentationLibrary is missing'
);

const spans = instrumentationLibrarySpans[0].spans;
assert.strictEqual(spans && spans.length, 1, 'spans are missing');
assert.deepStrictEqual(resource, {
attributes: [
{
'key': 'service.name',
'value': {
'stringValue': `unknown_service:${process.argv0}`,
'value': 'stringValue'
}
},
{
'key': 'telemetry.sdk.language',
'value': {
'stringValue': 'nodejs',
'value': 'stringValue'
}
},
{
'key': 'telemetry.sdk.name',
'value': {
'stringValue': 'opentelemetry',
'value': 'stringValue'
}
},
{
'key': 'telemetry.sdk.version',
'value': {
'stringValue': VERSION,
'value': 'stringValue'
}
},
{
key: 'service',
value: {
stringValue: 'ui',
value: 'stringValue',
},
},
{
key: 'version',
value: {
intValue: '1',
value: 'intValue',
},
},
{
key: 'cost',
value: {
doubleValue: 112.12,
value: 'doubleValue',
},
},
],
droppedAttributesCount: 0,
});
}

export class MockedResponse extends Stream {
constructor(private _code: number, private _msg?: string) {
super();
}

send(data: string) {
this.emit('data', data);
this.emit('end');
}

get statusCode() {
return this._code;
}

get statusMessage() {
return this._msg;
}
export function ensureMetadataIsCorrect(
actual: grpc.Metadata,
expected: grpc.Metadata
) {
//ignore user agent
expected.remove('user-agent');
actual.remove('user-agent');
assert.deepStrictEqual(actual.getMap(), expected.getMap());
}
Loading