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

refactor(exporters): introduce packages for shared exporter classes #2893

Merged
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
112452a
refactor(trace-exporter): move base otlp exporter to an otlp-exporter…
pichlermarc Apr 5, 2022
18cf3c5
refactor(trace-exporter): make exporter-trace-otlp-grpc use the otlp-…
pichlermarc Apr 6, 2022
0081942
refactor(trace-exporter): make exporter-trace-otlp-proto use the otlp…
pichlermarc Apr 6, 2022
427c8ee
refactor(metrics-exporter): make exporter-metrics-otlp-http use the o…
pichlermarc Apr 6, 2022
421197d
refactor(metrics-exporter): make exporter-metrics-otlp-grpc use the o…
pichlermarc Apr 6, 2022
42f32e8
refactor(metrics-exporter): make exporter-metrics-otlp-proto use the …
pichlermarc Apr 6, 2022
7e0f76b
refactor(exporters): add opentelemetry-core dependency to otlp-export…
pichlermarc Apr 6, 2022
5da4d3b
refactor(exporters): introduce otlp-grpc-exporter-base.
pichlermarc Apr 6, 2022
bbfb8e9
refactor(gprc-exporters): make grpc exporters use trace package.
pichlermarc Apr 8, 2022
7d02676
refactor(trace-exporter-otlp-http): update log mocking for browser te…
pichlermarc Apr 8, 2022
a10d9e8
refactor(metrics-exporter): introduce the otlp-proto-exporter-base pa…
pichlermarc Apr 8, 2022
5dbd776
refactor(otlp-proto-exporter-base): use correct protos.
pichlermarc Apr 8, 2022
1450ec0
refactor(grpc-exporter-base): replace double quote string with single…
pichlermarc Apr 8, 2022
5bedcde
refactor(exporters): cleanup.
pichlermarc Apr 8, 2022
994c447
chore: changelog
dyladan Apr 14, 2022
d4fa873
Merge branch 'main' into introduce-otlp-exporter-base
dyladan Apr 15, 2022
d9d0a67
chore: add codecov script
dyladan Apr 15, 2022
6881eb7
chore: move base to devDependencies
dyladan Apr 18, 2022
d26465f
chore: fix import alignment
dyladan Apr 18, 2022
f4ff559
chore: remove unused dependency
dyladan Apr 18, 2022
90c96a2
Merge remote-tracking branch 'origin/main' into introduce-otlp-export…
dyladan Apr 18, 2022
5d0ae75
Merge branch 'main' into introduce-otlp-exporter-base
pichlermarc Apr 19, 2022
996bb32
refactor(exporter-base): relax dependencies to @opentelemetry/api
pichlermarc Apr 19, 2022
161fcc8
refactor(otlp-trace-exporter): add tests to gain back lost coverage.
pichlermarc Apr 19, 2022
4be67e6
Merge branch 'main' into introduce-otlp-exporter-base
dyladan Apr 19, 2022
fb92286
refactor(exporter-base): clean up package.json files
pichlermarc Apr 20, 2022
d138210
refactor(otlp-exporter-base): cleanup dependencies.
pichlermarc Apr 20, 2022
bad13f7
Merge branch 'open-telemetry:main' into introduce-otlp-exporter-base
pichlermarc Apr 20, 2022
246a4fa
refactor(otlp-trace-exporter): try to gain back lost coverage.
pichlermarc Apr 20, 2022
8d83a17
Merge branch 'main' into introduce-otlp-exporter-base
pichlermarc Apr 21, 2022
b45d71a
fix(exporter-base): update code coverage paths.
pichlermarc Apr 21, 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
14 changes: 4 additions & 10 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
[submodule "experimental/packages/exporter-trace-otlp-proto/protos"]
path = experimental/packages/exporter-trace-otlp-proto/protos
[submodule "experimental/packages/otlp-grpc-exporter-base/protos"]
path = experimental/packages/otlp-grpc-exporter-base/protos
url = https://github.com/open-telemetry/opentelemetry-proto.git
[submodule "experimental/packages/exporter-trace-otlp-grpc/protos"]
path = experimental/packages/exporter-trace-otlp-grpc/protos
url = https://github.com/open-telemetry/opentelemetry-proto.git
[submodule "experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/protos"]
path = experimental/packages/opentelemetry-exporter-metrics-otlp-grpc/protos
url = https://github.com/open-telemetry/opentelemetry-proto.git
[submodule "experimental/packages/opentelemetry-exporter-metrics-otlp-proto/protos"]
path = experimental/packages/opentelemetry-exporter-metrics-otlp-proto/protos
[submodule "experimental/packages/otlp-proto-exporter-base/protos"]
path = experimental/packages/otlp-proto-exporter-base/protos
url = https://github.com/open-telemetry/opentelemetry-proto.git
4 changes: 4 additions & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ All notable changes to experimental packages in this project will be documented
* updated `opentelemetry-sdk-node` to the latest Metrics SDK.
* updated `otlp-transformer` to the latest Metrics SDK.
* updated all `instrumentation-*` packages to use local implementations of `parseUrl()` due to #2884
* refactor(otlp-exporters) move base classes and associated types into their own packages #2893 @pichlermarc
* `otlp-exporter-base` => `OTLPExporterBase`, `OTLPExporterBrowserBase`, `OTLPExporterNodeBase`
* `otlp-grpc-exporter-base` => `OTLPGRPCExporterNodeBase`
* `otlp-proto-exporter-base` => `OTLPProtoExporterNodeBase`

### :rocket: (Enhancement)

Expand Down
7 changes: 3 additions & 4 deletions experimental/packages/exporter-trace-otlp-grpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@
"clean": "tsc --build --clean",
"lint": "eslint . --ext .ts",
"lint:fix": "eslint . --ext .ts --fix",
"postcompile": "npm run submodule && npm run protos:copy",
"protos:copy": "cpx protos/opentelemetry/**/*.* build/protos/opentelemetry",
"submodule": "git submodule sync --recursive && git submodule update --init --recursive",
"tdd": "npm run test -- --watch-extensions ts --watch",
"test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'",
"version": "node ../../../scripts/version-update.js",
"watch": "npm run protos:copy && tsc -w",
"watch": "tsc -w",
"precompile": "lerna run version --scope $(npm pkg get name) --include-dependencies",
"prewatch": "npm run precompile"
},
Expand Down Expand Up @@ -71,6 +68,8 @@
"@grpc/grpc-js": "^1.5.9",
"@grpc/proto-loader": "^0.6.9",
"@opentelemetry/exporter-trace-otlp-http": "0.27.0",
"@opentelemetry/otlp-exporter-base": "0.27.0",
dyladan marked this conversation as resolved.
Show resolved Hide resolved
"@opentelemetry/otlp-grpc-exporter-base": "0.27.0",
"@opentelemetry/resources": "1.1.1",
"@opentelemetry/sdk-trace-base": "1.1.1"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,30 @@
*/

import { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';
import { OTLPExporterNodeBase } from './OTLPExporterNodeBase';
import {
otlpTypes,
toOTLPExportTraceServiceRequest,
} from '@opentelemetry/exporter-trace-otlp-http';
import { OTLPExporterConfigNode, ServiceClientType } from './types';
import { baggageUtils, getEnv } from '@opentelemetry/core';
import { validateAndNormalizeUrl } from './util';
import { Metadata } from '@grpc/grpc-js';
import {
OTLPGRPCExporterConfigNode,
OTLPGRPCExporterNodeBase,
ServiceClientType,
validateAndNormalizeUrl
} from '@opentelemetry/otlp-grpc-exporter-base';

const DEFAULT_COLLECTOR_URL = 'localhost:4317';

/**
* OTLP Trace Exporter for Node
*/
export class OTLPTraceExporter
extends OTLPExporterNodeBase<
ReadableSpan,
otlpTypes.opentelemetryProto.collector.trace.v1.ExportTraceServiceRequest
>
extends OTLPGRPCExporterNodeBase<ReadableSpan,
otlpTypes.opentelemetryProto.collector.trace.v1.ExportTraceServiceRequest>
implements SpanExporter {

constructor(config: OTLPExporterConfigNode = {}) {
constructor(config: OTLPGRPCExporterConfigNode = {}) {
super(config);
const headers = baggageUtils.parseKeyPairsIntoRecord(getEnv().OTEL_EXPORTER_OTLP_TRACES_HEADERS);
this.metadata ||= new Metadata();
Expand All @@ -52,14 +53,14 @@ export class OTLPTraceExporter
return toOTLPExportTraceServiceRequest(spans, this);
}

getDefaultUrl(config: OTLPExporterConfigNode) {
getDefaultUrl(config: OTLPGRPCExporterConfigNode) {
return typeof config.url === 'string'
? validateAndNormalizeUrl(config.url)
: getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0
? validateAndNormalizeUrl(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT)
: getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0
? validateAndNormalizeUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT)
: DEFAULT_COLLECTOR_URL;
? validateAndNormalizeUrl(getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT)
: getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0
? validateAndNormalizeUrl(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT)
: DEFAULT_COLLECTOR_URL;
}

getServiceClientType() {
Expand Down
3 changes: 0 additions & 3 deletions experimental/packages/exporter-trace-otlp-grpc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,4 @@
* limitations under the License.
*/

export * from './OTLPExporterNodeBase';
export * from './OTLPTraceExporter';
export { ServiceClientType, OTLPExporterConfigNode } from './types';
export { validateAndNormalizeUrl } from './util';
46 changes: 0 additions & 46 deletions experimental/packages/exporter-trace-otlp-grpc/submodule.md

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ import {
ensureResourceIsCorrect,
mockedReadableSpan,
} from './traceHelper';

import { CompressionAlgorithm } from '../src/types';
import { CompressionAlgorithm } from '@opentelemetry/otlp-exporter-base';
import { GrpcCompressionAlgorithm } from '@opentelemetry/otlp-grpc-exporter-base';

const traceServiceProtoPath =
'opentelemetry/proto/collector/trace/v1/trace_service.proto';
const includeDirs = [path.resolve(__dirname, '../protos')];
const includeDirs = [path.resolve(__dirname, '../../otlp-grpc-exporter-base/protos')];

const address = 'localhost:1501';

Expand Down Expand Up @@ -267,7 +267,7 @@ const testCollectorExporter = (params: TestParams) =>
credentials,
metadata: params.metadata,
});
assert.strictEqual(collectorExporter.compression, CompressionAlgorithm.GZIP);
assert.strictEqual(collectorExporter.compression, GrpcCompressionAlgorithm.GZIP);
delete envSource.OTEL_EXPORTER_OTLP_COMPRESSION;
});
});
Expand Down Expand Up @@ -337,3 +337,5 @@ describe('when configuring via environment', () => {
testCollectorExporter({ useTLS: true });
testCollectorExporter({ useTLS: false });
testCollectorExporter({ metadata });


Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
"references": [
{
"path": "../exporter-trace-otlp-http"
},
{
"path": "../otlp-exporter-base"
},
{
"path": "../otlp-grpc-exporter-base"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"dependencies": {
"@opentelemetry/core": "1.1.1",
"@opentelemetry/resources": "1.1.1",
"@opentelemetry/sdk-trace-base": "1.1.1"
"@opentelemetry/sdk-trace-base": "1.1.1",
"@opentelemetry/otlp-exporter-base": "0.27.0"
}
}
2 changes: 0 additions & 2 deletions experimental/packages/exporter-trace-otlp-http/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
* limitations under the License.
*/

export * from './OTLPExporterBase';
export * from './platform';
export * as otlpTypes from './types';
export { toCollectorResource, toOTLPExportTraceServiceRequest } from './transform';
export { appendResourcePathToUrlIfNotPresent } from './util';
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@
* limitations under the License.
*/

import { OTLPExporterConfigBase } from '../../types';
import { OTLPExporterBrowserBase } from './OTLPExporterBrowserBase';
import { appendResourcePathToUrlIfNotPresent, OTLPExporterBrowserBase } from '@opentelemetry/otlp-exporter-base';
import { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';
import { toOTLPExportTraceServiceRequest } from '../../transform';
import * as otlpTypes from '../../types';
import { getEnv, baggageUtils } from '@opentelemetry/core';
import { appendResourcePathToUrlIfNotPresent } from '../../util';
import { OTLPExporterConfigBase } from '@opentelemetry/otlp-exporter-base';

const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/traces';
const DEFAULT_COLLECTOR_URL=`http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@
*/

export * from './OTLPTraceExporter';
export * from './OTLPExporterBrowserBase';
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@
*/

export * from './node';
export { OTLPExporterBrowserBase } from './browser';
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,24 @@
*/

import { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';
import { OTLPExporterNodeBase } from './OTLPExporterNodeBase';
import { OTLPExporterNodeConfigBase } from './types';
import * as otlpTypes from '../../types';
import { toOTLPExportTraceServiceRequest } from '../../transform';
import { getEnv, baggageUtils } from '@opentelemetry/core';
import { appendResourcePathToUrlIfNotPresent } from '../../util';
import { OTLPExporterNodeBase } from '@opentelemetry/otlp-exporter-base';
import {
OTLPExporterNodeConfigBase,
appendResourcePathToUrlIfNotPresent
} from '@opentelemetry/otlp-exporter-base';

const DEFAULT_COLLECTOR_RESOURCE_PATH = '/v1/traces';
const DEFAULT_COLLECTOR_URL=`http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`;
const DEFAULT_COLLECTOR_URL = `http://localhost:4318${DEFAULT_COLLECTOR_RESOURCE_PATH}`;

/**
* Collector Trace Exporter for Node
*/
export class OTLPTraceExporter
extends OTLPExporterNodeBase<
ReadableSpan,
otlpTypes.opentelemetryProto.collector.trace.v1.ExportTraceServiceRequest
>
extends OTLPExporterNodeBase<ReadableSpan,
otlpTypes.opentelemetryProto.collector.trace.v1.ExportTraceServiceRequest>
implements SpanExporter {
constructor(config: OTLPExporterNodeConfigBase = {}) {
super(config);
Expand All @@ -50,13 +50,13 @@ export class OTLPTraceExporter
return toOTLPExportTraceServiceRequest(spans, this, true);
}

getDefaultUrl(config: OTLPExporterNodeConfigBase) : string {
getDefaultUrl(config: OTLPExporterNodeConfigBase): string {
return typeof config.url === 'string'
? config.url
: getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT.length > 0
? getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
: getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0
? appendResourcePathToUrlIfNotPresent(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
: DEFAULT_COLLECTOR_URL;
? getEnv().OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
: getEnv().OTEL_EXPORTER_OTLP_ENDPOINT.length > 0
? appendResourcePathToUrlIfNotPresent(getEnv().OTEL_EXPORTER_OTLP_ENDPOINT, DEFAULT_COLLECTOR_RESOURCE_PATH)
: DEFAULT_COLLECTOR_URL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,3 @@
*/

export * from './OTLPTraceExporter';
export * from './OTLPExporterNodeBase';
export * from './util';
export * from './types';
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ import {
import * as core from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';
import { ReadableSpan, TimedEvent } from '@opentelemetry/sdk-trace-base';
import { OTLPExporterBase } from './OTLPExporterBase';
import {
OTLP_SPAN_KIND_MAPPING,
opentelemetryProto,
OTLPExporterConfigBase,
} from './types';
import { OTLPExporterBase, OTLPExporterConfigBase } from '@opentelemetry/otlp-exporter-base';

const MAX_INTEGER_VALUE = 2147483647;
const MIN_INTEGER_VALUE = -2147483648;
Expand Down
40 changes: 1 addition & 39 deletions experimental/packages/exporter-trace-otlp-http/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { SpanAttributes, SpanKind, SpanStatusCode } from '@opentelemetry/api';
import { SpanKind, SpanStatusCode } from '@opentelemetry/api';

/* eslint-disable @typescript-eslint/no-namespace */
/* eslint-disable @typescript-eslint/no-unused-vars */
Expand Down Expand Up @@ -311,44 +311,6 @@ export namespace opentelemetryProto {
}
}

/**
* Interface for handling error
*/
export class OTLPExporterError extends Error {
readonly code?: number;
override readonly name: string = 'OTLPExporterError';
readonly data?: string;

constructor(message?: string, code?: number, data?: string) {
super(message);
this.data = data;
this.code = code;
}
}

/**
* Interface for handling export service errors
*/
export interface ExportServiceError {
name: string;
code: number;
details: string;
metadata: { [key: string]: unknown };
message: string;
stack: string;
}

/**
* Collector Exporter base config
*/
export interface OTLPExporterConfigBase {
headers?: Partial<Record<string, unknown>>;
hostname?: string;
attributes?: SpanAttributes;
url?: string;
concurrencyLimit?: number;
}

/**
* Mapping between api SpanKind and proto SpanKind
*/
Expand Down
Loading