Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,33 @@ const config: ResolveConfigFn = (env: Env, trigger) => ({
- Both tracing and logging
- Neither (no telemetry)

### Custom Fetcher

```typescript
const config: ResolveConfigFn = (env: Env, trigger) => {
const { fetch } = env.VPC_BINDING
const fetcher = fetch.bind(env.VPC_BINDING)
return {
service: {
name: 'my-service',
version: '1.0.0', // Optional
namespace: 'production', // Optional
},
trace: {
exporter: {
fetcher,
url: env.TRACE_ENDPOINT,
headers: { 'signoz-access-token': env.SIGNOZ_ACCESS_TOKEN },
},
},
// Logs are optional
logs: {
transports: [new OTLPTransport({ fetcher, url: env.LOGS_ENDPOINT })],
},
}
}
```

### Sampling

```typescript
Expand Down
3 changes: 3 additions & 0 deletions src/exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ import { DEFAULT_OTLP_HEADERS } from './constants'
export interface OTLPExporterConfig {
url: string
headers?: Record<string, string>
fetcher?: Fetcher['fetch']
}

export class OTLPExporter implements SpanExporter {
private headers: Record<string, string>
private url: string
private fetcher: Fetcher['fetch']
constructor(config: OTLPExporterConfig) {
this.url = config.url
this.headers = Object.assign({}, DEFAULT_OTLP_HEADERS, config.headers)
this.fetcher = config.fetcher ?? fetch

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Custom fetcher unused in exporter

High Severity

OTLPExporter accepts and stores config.fetcher, but send still calls global fetch via unwrap(fetch) instead of this.fetcher. Custom fetchers (including VPC bindings shown in the README) are ignored for traces, while OTLPTransport correctly uses this.fetcher.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit d61092f. Configure here.

}

export(items: any[], resultCallback: (result: ExportResult) => void): void {
Expand Down
4 changes: 3 additions & 1 deletion src/logs/transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ export class OTLPTransport implements LogTransport {
private headers: Record<string, string>
private url: string
private minSeverity: number
private fetcher: Fetcher['fetch']

constructor(config: OTLPTransportConfig) {
this.url = config.url
this.headers = Object.assign({}, DEFAULT_OTLP_HEADERS, config.headers)
this.minSeverity = levelToSeverity(config.level ?? 'TRACE')
this.fetcher = config.fetcher ?? fetch
}

export(logs: ReadableLogRecord[], callback: ExportResultCallback): void {
Expand Down Expand Up @@ -79,7 +81,7 @@ export class OTLPTransport implements LogTransport {
body,
}

const response = await unwrap(fetch)(this.url, params)
const response = await unwrap(this.fetcher)(this.url, params)

if (!response.ok) {
throw new OTLPExporterError(`Exporter received a statusCode: ${response.status}`)
Expand Down
1 change: 1 addition & 0 deletions src/logs/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export interface OTLPTransportConfig {
url: string
headers?: Record<string, string>
level?: LogLevel
fetcher?: Fetcher['fetch']
}

export interface ConsoleTransportConfig {
Expand Down