Skip to content

Commit

Permalink
test: use a record-only sampler for test
Browse files Browse the repository at this point in the history
  • Loading branch information
quickgiant committed Aug 4, 2021
1 parent 9d66288 commit 0d41684
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import { diag } from '@opentelemetry/api';
import {
AlwaysOffSampler,
AlwaysOnSampler,
ExportResultCode,
loggingErrorHandler,
Expand All @@ -26,6 +25,7 @@ import * as assert from 'assert';
import * as sinon from 'sinon';
import { BasicTracerProvider, BufferConfig, InMemorySpanExporter, Span } from '../../../src';
import { context } from '@opentelemetry/api';
import { TestRecordOnlySampler } from './TestRecordOnlySampler';
import { TestTracingSpanExporter } from './TestTracingSpanExporter';
import { TestStackContextManager } from './TestStackContextManager';
import { BatchSpanProcessorBase } from '../../../src/export/BatchSpanProcessorBase';
Expand All @@ -41,7 +41,7 @@ function createSampledSpan(spanName: string): Span {

function createUnsampledSpan(spanName: string): Span {
const tracer = new BasicTracerProvider({
sampler: new AlwaysOffSampler(),
sampler: new TestRecordOnlySampler(),
}).getTracer('default');
const span = tracer.startSpan(spanName);
span.end();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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 { Sampler, SamplingDecision, SamplingResult } from '@opentelemetry/api';

/** Sampler that always records but doesn't sample spans. */
export class TestRecordOnlySampler implements Sampler {
shouldSample(): SamplingResult {
return {
decision: SamplingDecision.RECORD,
};
}

toString(): string {
return 'TestRecordOnlySampler';
}
}

0 comments on commit 0d41684

Please sign in to comment.