Skip to content

Commit

Permalink
Add opentelemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
yoonghan committed Jan 9, 2025
1 parent 9061aff commit 726404b
Show file tree
Hide file tree
Showing 3 changed files with 365 additions and 6 deletions.
36 changes: 36 additions & 0 deletions instrumentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { registerOTel } from "@vercel/otel"
import { SamplingDecision } from "@opentelemetry/sdk-trace-base"
import { trace, Context } from "@opentelemetry/api"

export function register() {
registerOTel({
serviceName: "acme-next-app",
traceExporter: "auto",
spanProcessors: ["auto"],
traceSampler: {
shouldSample: (context: Context) => {
const isChecklySpan = trace
.getSpan(context)
?.spanContext()
?.traceState?.get("checkly")
if (isChecklySpan) {
console.log(
"Sampling decision for Checkly span:",
SamplingDecision.RECORD_AND_SAMPLED
)
return {
decision: SamplingDecision.RECORD_AND_SAMPLED,
}
} else {
console.log(
"Sampling decision for non-Checkly span:",
SamplingDecision.NOT_RECORD
)
return {
decision: SamplingDecision.NOT_RECORD,
}
}
},
},
})
}
Loading

0 comments on commit 726404b

Please sign in to comment.