-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8af9342
commit 5de607e
Showing
4 changed files
with
69 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import * as traceloop from "@traceloop/node-server-sdk"; | ||
import { trace, Span, context } from "@opentelemetry/api"; | ||
import { ConsoleSpanExporter } from "@opentelemetry/sdk-trace-base"; | ||
|
||
trace.getTracer("traceloop.tracer"); | ||
|
||
// No spans should be printed to the console when this file runs (it should be filtered out by the sampler) | ||
|
||
const main = async () => { | ||
traceloop.initialize({ | ||
appName: "sample_sampler", | ||
apiKey: process.env.TRACELOOP_API_KEY, | ||
disableBatch: true, | ||
traceloopSyncEnabled: false, | ||
exporter: new ConsoleSpanExporter(), | ||
}); | ||
|
||
trace | ||
.getTracer("traceloop.tracer") | ||
.startActiveSpan( | ||
"test-span", | ||
{ attributes: { "next.span_name": "anything" } }, | ||
context.active(), | ||
async (span: Span) => { | ||
span.end(); | ||
}, | ||
); | ||
}; | ||
|
||
main(); |
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,36 @@ | ||
import { | ||
Sampler, | ||
SamplingResult, | ||
SamplingDecision, | ||
} from "@opentelemetry/sdk-trace-base"; | ||
import { Context, SpanKind, Attributes, Link } from "@opentelemetry/api"; | ||
|
||
const FILTERED_ATTRIBUTE_KEYS = ["next.span_name"]; | ||
|
||
export class TraceloopSampler implements Sampler { | ||
shouldSample( | ||
_context: Context, | ||
_traceId: string, | ||
_spanName: string, | ||
_spanKind: SpanKind, | ||
attributes: Attributes, | ||
_links: Link[], | ||
): SamplingResult { | ||
let filter = false; | ||
FILTERED_ATTRIBUTE_KEYS.forEach((key) => { | ||
if (attributes?.[key]) { | ||
filter = true; | ||
} | ||
}); | ||
|
||
return { | ||
decision: filter | ||
? SamplingDecision.NOT_RECORD | ||
: SamplingDecision.RECORD_AND_SAMPLED, | ||
}; | ||
} | ||
|
||
toString(): string { | ||
return "TraceloopSampler"; | ||
} | ||
} |