-
Notifications
You must be signed in to change notification settings - Fork 813
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add tracing suppresing for Metrics Export (#3332)
- Loading branch information
1 parent
bbc1811
commit 292a53d
Showing
6 changed files
with
108 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* 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): Promise<ExportResult> { | ||
return new Promise(resolve => { | ||
// prevent downstream exporter calls from generating spans | ||
context.with(suppressTracing(context.active()), () => { | ||
exporter.export(arg, (result: ExportResult) => { | ||
resolve(result); | ||
}); | ||
}); | ||
}); | ||
} |
43 changes: 43 additions & 0 deletions
43
packages/opentelemetry-core/test/internal/exporter.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* 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 * as assert from 'assert'; | ||
import * as sinon from 'sinon'; | ||
import { ExportResult, ExportResultCode } from '../../src'; | ||
import * as suppress from '../../src/trace/suppress-tracing'; | ||
import { _export } from '../../src/internal/exporter'; | ||
|
||
describe('exporter', () => { | ||
const sandbox = sinon.createSandbox(); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
class TestExporter { | ||
export(arg: any, resultCallback: (result: ExportResult) => void) { | ||
resultCallback({ code: ExportResultCode.SUCCESS }); | ||
} | ||
} | ||
|
||
it('_export should suppress tracing', async () => { | ||
const suppressSpy = sandbox.spy(suppress, 'suppressTracing'); | ||
const exporter = new TestExporter(); | ||
const result = await _export(exporter, ['Test1']); | ||
assert.strictEqual(result.code, ExportResultCode.SUCCESS); | ||
assert.ok(suppressSpy.calledOnce); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters