This repository has been archived by the owner on Oct 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: revert telemetry instrumentation to otlp (#13)
- Loading branch information
1 parent
471103f
commit d6f5289
Showing
28 changed files
with
2,911 additions
and
13,917 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
PORT= | ||
TRACING_SERVICE_NAME= | ||
TRACING_SERVICE_VERSION= | ||
ELASTIC_APM_ENDPOINT= | ||
ELASTIC_APM_TOKEN= | ||
THROTTLER_TTL_SECONDS= | ||
|
||
# telemetry | ||
OTEL_EXPORTER_OTLP_ENDPOINT= | ||
OTEL_SERVICE_NAME= | ||
OTEL_SERVICE_VERSION= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,38 @@ | ||
import { Body, Controller, Headers, Post } from '@nestjs/common' | ||
import { context, metrics, propagation, trace } from '@opentelemetry/api' | ||
|
||
import { GetSubnetAssetsDto } from './faucet.dto' | ||
import { FaucetService } from './faucet.service' | ||
|
||
@Controller('faucet') | ||
export class FaucetController { | ||
private _tracer = trace.getTracer('FaucetController') | ||
private _meter = metrics.getMeter('FaucetController') | ||
private _counter = this._meter.createCounter('get_subnet_assets.counter') | ||
|
||
constructor(private faucetService: FaucetService) {} | ||
|
||
@Post('getSubnetAssets') | ||
async getSubnetAssets( | ||
@Body() getSubnetAssetsDto: GetSubnetAssetsDto, | ||
@Headers('traceparent') traceparent: string | ||
@Headers('traceparent') traceparent?: string, | ||
@Headers('tracestate') tracestate?: string | ||
) { | ||
return this.faucetService.getSubnetAssets(getSubnetAssetsDto, traceparent) | ||
this._counter.add(1) | ||
|
||
const activeContext = propagation.extract(context.active(), { | ||
traceparent, | ||
tracestate, | ||
}) | ||
|
||
return context.with(activeContext, async () => { | ||
return this._tracer.startActiveSpan('getSubnetAssets', async (span) => { | ||
const receipts = await this.faucetService.getSubnetAssets( | ||
getSubnetAssetsDto | ||
) | ||
span.end() | ||
return receipts | ||
}) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
import { Module } from '@nestjs/common' | ||
|
||
import { ApmModule } from '../apm/apm.module' | ||
import { FaucetController } from './faucet.controller' | ||
import { FaucetService } from './faucet.service' | ||
|
||
@Module({ | ||
controllers: [FaucetController], | ||
imports: [ApmModule], | ||
providers: [FaucetService], | ||
}) | ||
export class FaucetModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Module } from '@nestjs/common' | ||
|
||
import { TelemetryService } from './telemetry.service' | ||
|
||
@Module({ | ||
exports: [TelemetryService], | ||
providers: [TelemetryService], | ||
}) | ||
export class TelemetryModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Injectable } from '@nestjs/common' | ||
|
||
// Uncomment to get otlp logs | ||
// import { | ||
// diag, | ||
// DiagConsoleLogger, | ||
// DiagLogLevel, | ||
// metrics, | ||
// } from '@opentelemetry/api' | ||
import { NodeSDK } from '@opentelemetry/sdk-node' | ||
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto' | ||
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-proto' | ||
import { PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics' | ||
|
||
const OTEL_EXPORTER_OTLP_ENDPOINT = | ||
process.env.OTEL_EXPORTER_OTLP_ENDPOINT || 'http://localhost:4318' | ||
|
||
@Injectable() | ||
export class TelemetryService { | ||
constructor() { | ||
// Uncomment to get otlp logs | ||
// diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG) | ||
|
||
const otelSDK = new NodeSDK({ | ||
traceExporter: new OTLPTraceExporter({ | ||
url: `${OTEL_EXPORTER_OTLP_ENDPOINT}/v1/traces`, | ||
}), | ||
metricReader: new PeriodicExportingMetricReader({ | ||
exporter: new OTLPMetricExporter({ | ||
url: `${OTEL_EXPORTER_OTLP_ENDPOINT}/v1/metrics`, | ||
}), | ||
}), | ||
instrumentations: [], | ||
}) | ||
|
||
otelSDK.start() | ||
|
||
// gracefully shut down the SDK on process exit | ||
process.on('SIGTERM', () => { | ||
otelSDK | ||
.shutdown() | ||
.then( | ||
() => console.log('SDK shut down successfully'), | ||
(err) => console.log('Error shutting down SDK', err) | ||
) | ||
.finally(() => process.exit(0)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function getErrorMessage(error: unknown) { | ||
return error instanceof Error ? error.message : String(error) | ||
} |
Oops, something went wrong.