Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tracing): enable setting a sampling ratio for tracing #143

Merged
merged 5 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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 src/bindings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ export interface Environment
CONTENT_CLAIMS_SERVICE_URL?: string
HONEYCOMB_API_KEY: string
FF_TELEMETRY_ENABLED: string
TELEMETRY_RATIO: string
}
12 changes: 10 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
withDelegationStubs
} from './middleware/index.js'
import { instrument } from '@microlabs/otel-cf-workers'
import { NoopSpanProcessor } from '@opentelemetry/sdk-trace-base'
import { NoopSpanProcessor, TraceIdRatioBasedSampler } from '@opentelemetry/sdk-trace-base'

/**
* @import {
Expand Down Expand Up @@ -101,6 +101,7 @@ const middleware = composeMiddleware(
*
* @param {Environment} env
* @param {*} _trigger
* @returns {import('@microlabs/otel-cf-workers').TraceConfig}
*/
function config (env, _trigger) {
if (env.HONEYCOMB_API_KEY) {
Expand All @@ -109,7 +110,14 @@ function config (env, _trigger) {
url: 'https://api.honeycomb.io/v1/traces',
headers: { 'x-honeycomb-team': env.HONEYCOMB_API_KEY }
},
service: { name: 'freeway' }
service: { name: 'freeway' },
...(env.TELEMETRY_RATIO
? {
sampling: {
headSampler: new TraceIdRatioBasedSampler(parseFloat(env.TELEMETRY_RATIO))
}
}
: {})
}
}
return {
Expand Down
8 changes: 8 additions & 0 deletions wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ MAX_SHARDS = "825"
FF_RATE_LIMITER_ENABLED = "false"
FF_EGRESS_TRACKER_ENABLED = "true"
FF_TELEMETRY_ENABLED = "true"
TELEMETRY_RATIO = 0.01
FF_DELEGATIONS_STORAGE_ENABLED = "true"
FF_RAMP_UP_PROBABILITY = "0"
GATEWAY_SERVICE_DID = "did:web:w3s.link"
Expand Down Expand Up @@ -82,6 +83,7 @@ MAX_SHARDS = "825"
FF_RATE_LIMITER_ENABLED = "false"
FF_EGRESS_TRACKER_ENABLED = "true"
FF_TELEMETRY_ENABLED = "true"
TELEMETRY_RATIO = 1.0
FF_DELEGATIONS_STORAGE_ENABLED = "true"
FF_RAMP_UP_PROBABILITY = "100"
GATEWAY_SERVICE_DID = "did:web:staging.w3s.link"
Expand All @@ -104,6 +106,7 @@ DEBUG = "true"
FF_RATE_LIMITER_ENABLED = "false"
FF_EGRESS_TRACKER_ENABLED = "false"
FF_TELEMETRY_ENABLED = "true"
TELEMETRY_RATIO = 1.0
FF_RAMP_UP_PROBABILITY = "100"
MAX_SHARDS = "120"
GATEWAY_SERVICE_DID = "did:web:staging.w3s.link"
Expand All @@ -123,6 +126,7 @@ DEBUG = "true"
FF_RATE_LIMITER_ENABLED = "false"
FF_EGRESS_TRACKER_ENABLED = "false"
FF_TELEMETRY_ENABLED = "true"
TELEMETRY_RATIO = 1.0
GATEWAY_SERVICE_DID = "did:web:staging.w3s.link"
UPLOAD_SERVICE_DID = "did:web:staging.web3.storage"
CONTENT_CLAIMS_SERVICE_URL = "https://dev.claims.web3.storage"
Expand All @@ -149,6 +153,7 @@ DEBUG = "true"
FF_RATE_LIMITER_ENABLED = "false"
FF_EGRESS_TRACKER_ENABLED = "true"
FF_TELEMETRY_ENABLED = "true"
TELEMETRY_RATIO = 1.0
FF_DELEGATIONS_STORAGE_ENABLED = "true"
FF_RAMP_UP_PROBABILITY = "100"
GATEWAY_SERVICE_DID = "did:web:staging.w3s.link"
Expand Down Expand Up @@ -176,6 +181,7 @@ DEBUG = "true"
FF_RATE_LIMITER_ENABLED = "false"
FF_EGRESS_TRACKER_ENABLED = "false"
FF_TELEMETRY_ENABLED = "true"
TELEMETRY_RATIO = 1.0
GATEWAY_SERVICE_DID = "did:web:staging.w3s.link"
UPLOAD_SERVICE_DID = "did:web:staging.web3.storage"
CONTENT_CLAIMS_SERVICE_URL = "https://claims.web3.storage"
Expand All @@ -201,6 +207,7 @@ DEBUG = "true"
FF_RATE_LIMITER_ENABLED = "false"
FF_EGRESS_TRACKER_ENABLED = "true"
FF_TELEMETRY_ENABLED = "false"
TELEMETRY_RATIO = 1.0
GATEWAY_SERVICE_DID = "did:web:staging.w3s.link"
UPLOAD_SERVICE_DID = "did:web:staging.web3.storage"
CONTENT_CLAIMS_SERVICE_URL = "https://staging.claims.web3.storage"
Expand Down Expand Up @@ -233,6 +240,7 @@ DEBUG = "true"
FF_RATE_LIMITER_ENABLED = "true"
FF_EGRESS_TRACKER_ENABLED = "true"
FF_TELEMETRY_ENABLED = "true"
TELEMETRY_RATIO = 1.0
GATEWAY_SERVICE_DID = "did:web:staging.w3s.link"
UPLOAD_SERVICE_DID = "did:web:staging.web3.storage"
CONTENT_CLAIMS_SERVICE_URL = "https://staging.claims.web3.storage"
Expand Down
Loading