Skip to content

Commit

Permalink
add more debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
mojotalantikite committed Nov 16, 2023
1 parent ca8438a commit b79cf68
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions services/uploads/src/lib/otel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,26 @@ export function initTracer(serviceName: string, otelCollectorURL: string) {
}

export function initMeter(serviceName: string) {
const resource = Resource.default().merge(
new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: serviceName,
try {
const resource = Resource.default().merge(
new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: serviceName,
})
)
const metricReader = new PeriodicExportingMetricReader({
exporter: new OTLPMetricExporter(),
exportIntervalMillis: 1000,
})
)
const metricReader = new PeriodicExportingMetricReader({
exporter: new OTLPMetricExporter(),
exportIntervalMillis: 1000,
})

const provider = new MeterProvider({
resource: resource,
})
const provider = new MeterProvider({
resource: resource,
})

provider.addMetricReader(metricReader)
opentelemetry.metrics.setGlobalMeterProvider(provider)
provider.addMetricReader(metricReader)
opentelemetry.metrics.setGlobalMeterProvider(provider)
} catch (err) {
console.error('Failed to initialize otel meter', err)
}
}

export function recordException(
Expand All @@ -77,7 +81,14 @@ export function recordHistogram(
metricName: string,
executionTime: number
) {
const meter = opentelemetry.metrics.getMeterProvider().getMeter(serviceName)
const timeAvScan = meter.createHistogram(metricName)
timeAvScan.record(executionTime)
try {
const meter = opentelemetry.metrics
.getMeterProvider()
.getMeter(serviceName)
const timeAvScan = meter.createHistogram(metricName)
console.info('Recording histogram', metricName, executionTime)
timeAvScan.record(executionTime)
} catch (err) {
console.error('Failed to record histogram', err)
}
}

0 comments on commit b79cf68

Please sign in to comment.