Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
1 change: 1 addition & 0 deletions experimental/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ All notable changes to experimental packages in this project will be documented

### :rocket: (Enhancement)

* feat(metrics-sdk): Add tracing suppresing for Metrics Export [#3332](https://github.com/open-telemetry/opentelemetry-js/pull/3332) @hectorhdzg
* feat(sdk-node): configure trace exporter with environment variables [#3143](https://github.com/open-telemetry/opentelemetry-js/pull/3143) @svetlanabrennan
* feat(prometheus): serialize resource as target_info gauge [#3300](https://github.com/open-telemetry/opentelemetry-js/pull/3300) @pichlermarc

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import * as api from '@opentelemetry/api';
import {
ExportResultCode,
coreExport,
globalErrorHandler,
unrefTimer
} from '@opentelemetry/core';
Expand Down Expand Up @@ -86,7 +87,7 @@ export class PeriodicExportingMetricReader extends MetricReader {
}

return new Promise((resolve, reject) => {
this._exporter.export(resourceMetrics, result => {
coreExport(this._exporter, resourceMetrics, result => {
if (result.code !== ExportResultCode.SUCCESS) {
reject(
result.error ??
Expand Down
34 changes: 34 additions & 0 deletions packages/opentelemetry-core/src/Exporter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { context } from '@opentelemetry/api';
import { ExportResult } from './ExportResult';
import { suppressTracing } from './trace/suppress-tracing';

export interface Exporter<T> {
export(arg: T, resultCallback: (result: ExportResult) => void): void;
}

/**
* @internal
* Shared functionality used by Exporters while exporting data, including suppresion of Traces.
*/
export function _export<T>(exporter: Exporter<T>, arg: T, resultCallback: (result: ExportResult) => void): void {
// prevent downstream exporter calls from generating spans
context.with(suppressTracing(context.active()), () => {
exporter.export(arg, resultCallback);
});
}
1 change: 1 addition & 0 deletions packages/opentelemetry-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export * from './common/global-error-handler';
export * from './common/logging-error-handler';
export * from './common/time';
export * from './common/types';
export * from './Exporter';
export * from './ExportResult';
export * from './version';
export * as baggageUtils from './baggage/utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* limitations under the License.
*/

import { context, Context, TraceFlags } from '@opentelemetry/api';
import { Context, TraceFlags } from '@opentelemetry/api';
import {
ExportResultCode,
globalErrorHandler,
suppressTracing,
BindOnceFuture,
coreExport,
} from '@opentelemetry/core';
import { Span } from '../Span';
import { SpanProcessor } from '../SpanProcessor';
Expand All @@ -45,7 +45,7 @@ export class SimpleSpanProcessor implements SpanProcessor {
}

// does nothing.
onStart(_span: Span, _parentContext: Context): void {}
onStart(_span: Span, _parentContext: Context): void { }

onEnd(span: ReadableSpan): void {
if (this._shutdownOnce.isCalled) {
Expand All @@ -56,18 +56,15 @@ export class SimpleSpanProcessor implements SpanProcessor {
return;
}

// prevent downstream exporter calls from generating spans
context.with(suppressTracing(context.active()), () => {
this._exporter.export([span], result => {
if (result.code !== ExportResultCode.SUCCESS) {
globalErrorHandler(
result.error ??
new Error(
`SimpleSpanProcessor: span export failed (status ${result})`
)
);
}
});
coreExport(this._exporter, [span], result => {
if (result.code !== ExportResultCode.SUCCESS) {
globalErrorHandler(
result.error ??
new Error(
`SimpleSpanProcessor: span export failed (status ${result})`
)
);
}
});
}

Expand Down