Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/thirty-flies-swim.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'highlight.run': patch
---

tune opentelemetry traces export from highlight.run
27 changes: 15 additions & 12 deletions sdk/client/src/otel/exporter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http'
import type { ReadableSpan } from '@opentelemetry/sdk-trace-web'
import { OTLPExporterError } from '@opentelemetry/otlp-exporter-base'
import { MAX_PUBLIC_GRAPH_RETRY_ATTEMPTS } from '../utils/graph'

type ExporterConfig = ConstructorParameters<typeof OTLPTraceExporter>[0]
type SendOnErrorCallback = Parameters<OTLPTraceExporter['send']>[2]
Expand Down Expand Up @@ -28,19 +30,20 @@ export class OTLPTraceExporterBrowserWithXhrRetry extends OTLPTraceExporter {
onSuccess: () => void,
onError: SendOnErrorCallback,
): void {
super.send(items, onSuccess, (error) => {
if (error.message.toLocaleLowerCase().includes('beacon')) {
this.xhrTraceExporter.send(items, onSuccess, (xhrError) => {
onError({
...error,
message: `${error.message} --- [XHR retry message: ${xhrError.message}; code: ${xhrError.code}].`,
code: error.code,
data: `${error.data} --- [XHR retry data: ${xhrError.data}].`,
})
})
} else {
let retries = 0
const retry = (error: OTLPExporterError) => {
retries++
if (retries > MAX_PUBLIC_GRAPH_RETRY_ATTEMPTS) {
console.error(
`[highlight.io] failed to export OTeL traces: ${error.message}`,
error,
)
onError(error)
} else {
this.xhrTraceExporter.send(items, onSuccess, retry)
}
})
}

super.send(items, onSuccess, retry)
}
}
11 changes: 9 additions & 2 deletions sdk/client/src/otel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,21 @@ export const setupBrowserTracing = (config: BrowserTracingConfig) => {

const exporter = new OTLPTraceExporterBrowserWithXhrRetry({
url: config.otlpEndpoint + '/v1/traces',
concurrencyLimit: 10,
concurrencyLimit: 100,
timeoutMillis: 30_000,
// Using any because we were getting an error importing CompressionAlgorithm
// from @opentelemetry/otlp-exporter-base.
compression: 'gzip' as any,
keepAlive: true,
httpAgentOptions: {
timeout: 30_000,
keepAlive: true,
},
})

const spanProcessor = new CustomBatchSpanProcessor(exporter, {
maxExportBatchSize: 15,
maxExportBatchSize: 100,
maxQueueSize: 1_000,
})
provider.addSpanProcessor(spanProcessor)

Expand Down
Loading