Skip to content

Commit

Permalink
chore: update Mikro-ORM packages and more OTEL related fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
evereq committed Mar 7, 2024
1 parent 230303b commit 2ecb746
Show file tree
Hide file tree
Showing 10 changed files with 281 additions and 129 deletions.
3 changes: 2 additions & 1 deletion .env.compose
Original file line number Diff line number Diff line change
Expand Up @@ -386,13 +386,14 @@ JITSU_SERVER_ECHO_EVENTS=

# Tracing Configuration
OTEL_ENABLED=false
OTEL_PROVIDER=
OTEL_PROVIDER=zipkin
OTEL_SERVICE_NAME=
OTEL_EXPORTER_OTLP_PROTOCOL=
OTEL_EXPORTER_OTLP_HEADERS=
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=
OTEL_EXPORTER_OTLP_ENDPOINT=
ASPECTO_API_KEY=
HONEYCOMB_API_KEY=
HONEYCOMB_ENABLE_LOCAL_VISUALIZATIONS=

Expand Down
3 changes: 2 additions & 1 deletion .env.demo.compose
Original file line number Diff line number Diff line change
Expand Up @@ -388,13 +388,14 @@ JITSU_SERVER_ECHO_EVENTS=

# Tracing Configuration
OTEL_ENABLED=false
OTEL_PROVIDER=
OTEL_PROVIDER=zipkin
OTEL_SERVICE_NAME=
OTEL_EXPORTER_OTLP_PROTOCOL=
OTEL_EXPORTER_OTLP_HEADERS=
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=
OTEL_EXPORTER_OTLP_ENDPOINT=
ASPECTO_API_KEY=
HONEYCOMB_API_KEY=
HONEYCOMB_ENABLE_LOCAL_VISUALIZATIONS=

Expand Down
3 changes: 2 additions & 1 deletion .env.docker
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,14 @@ JITSU_SERVER_ECHO_EVENTS=

# Tracing Configuration
OTEL_ENABLED=false
OTEL_PROVIDER=
OTEL_PROVIDER=zipkin
OTEL_SERVICE_NAME=
OTEL_EXPORTER_OTLP_PROTOCOL=
OTEL_EXPORTER_OTLP_HEADERS=
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=
OTEL_EXPORTER_OTLP_ENDPOINT=
ASPECTO_API_KEY=
HONEYCOMB_API_KEY=
HONEYCOMB_ENABLE_LOCAL_VISUALIZATIONS=

Expand Down
3 changes: 2 additions & 1 deletion .env.local
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,14 @@ JITSU_SERVER_ECHO_EVENTS=

# Tracing Configuration
OTEL_ENABLED=false
OTEL_PROVIDER=
OTEL_PROVIDER=zipkin
OTEL_SERVICE_NAME=
OTEL_EXPORTER_OTLP_PROTOCOL=
OTEL_EXPORTER_OTLP_HEADERS=
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=
OTEL_EXPORTER_OTLP_ENDPOINT=
ASPECTO_API_KEY=
HONEYCOMB_API_KEY=
HONEYCOMB_ENABLE_LOCAL_VISUALIZATIONS=

Expand Down
3 changes: 2 additions & 1 deletion .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -378,13 +378,14 @@ JITSU_SERVER_ECHO_EVENTS=

# Tracing Configuration
OTEL_ENABLED=false
OTEL_PROVIDER=
OTEL_PROVIDER=zipkin
OTEL_SERVICE_NAME=
OTEL_EXPORTER_OTLP_PROTOCOL=
OTEL_EXPORTER_OTLP_HEADERS=
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT=
OTEL_EXPORTER_OTLP_ENDPOINT=
ASPECTO_API_KEY=
HONEYCOMB_API_KEY=
HONEYCOMB_ENABLE_LOCAL_VISUALIZATIONS=

Expand Down
23 changes: 11 additions & 12 deletions docker-compose.build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,18 @@ services:
networks:
- overlay

jaeger:
image: jaegertracing/all-in-one:latest
container_name: jaeger
zipkin:
image: ghcr.io/openzipkin/zipkin-slim:latest
container_name: zipkin
# Environment settings are defined here https://github.com/openzipkin/zipkin/blob/master/zipkin-server/README.md#environment-variables
environment:
- STORAGE_TYPE=mem
# Uncomment to enable self-tracing
# - SELF_TRACING_ENABLED=true
# Uncomment to increase heap size
# - JAVA_OPTS=-Xms128m -Xmx128m -XX:+ExitOnOutOfMemoryError
ports:
- 6831:6831/udp
- 6832:6832/udp
- 5778:5778
- 16686:16686
- 4317:4317
- 4318:4318
- 14250:14250
- 14268:14268
- 14269:14269
# Port used for the Zipkin UI and HTTP Api
- 9411:9411
networks:
- overlay
Expand Down
23 changes: 11 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,18 @@ services:
networks:
- overlay

jaeger:
image: jaegertracing/all-in-one:latest
container_name: jaeger
zipkin:
image: ghcr.io/openzipkin/zipkin-slim:latest
container_name: zipkin
# Environment settings are defined here https://github.com/openzipkin/zipkin/blob/master/zipkin-server/README.md#environment-variables
environment:
- STORAGE_TYPE=mem
# Uncomment to enable self-tracing
# - SELF_TRACING_ENABLED=true
# Uncomment to increase heap size
# - JAVA_OPTS=-Xms128m -Xmx128m -XX:+ExitOnOutOfMemoryError
ports:
- 6831:6831/udp
- 6832:6832/udp
- 5778:5778
- 16686:16686
- 4317:4317
- 4318:4318
- 14250:14250
- 14268:14268
- 14269:14269
# Port used for the Zipkin UI and HTTP Api
- 9411:9411
networks:
- overlay
Expand Down
15 changes: 8 additions & 7 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@
"@godaddy/terminus": "^4.12.1",
"@grpc/grpc-js": "^1.7.3",
"@jitsu/js": "^1.8.2",
"@mikro-orm/better-sqlite": "^6.0.5",
"@mikro-orm/core": "^6.0.5",
"@mikro-orm/knex": "^6.0.5",
"@mikro-orm/mongodb": "^6.0.5",
"@mikro-orm/mysql": "^6.0.5",
"@mikro-orm/better-sqlite": "^6.1.8",
"@mikro-orm/core": "^6.1.8",
"@mikro-orm/knex": "^6.1.8",
"@mikro-orm/mongodb": "^6.1.8",
"@mikro-orm/mysql": "^6.1.8",
"@mikro-orm/nestjs": "^5.2.3",
"@mikro-orm/postgresql": "^6.0.5",
"@mikro-orm/sqlite": "^6.0.5",
"@mikro-orm/postgresql": "^6.1.8",
"@mikro-orm/sqlite": "^6.1.8",
"@nestjs/apollo": "^12.1.0",
"@nestjs/axios": "^3.0.2",
"@nestjs/cache-manager": "^2.2.1",
Expand Down Expand Up @@ -108,6 +108,7 @@
"@opentelemetry/instrumentation": "^0.48.0",
"@opentelemetry/exporter-metrics-otlp-grpc": "^0.48.0",
"@opentelemetry/exporter-metrics-otlp-proto": "^0.48.0",
"opentelemetry-instrumentation-typeorm": "^0.40.0",
"@honeycombio/opentelemetry-node": "0.6.1",
"@sentry/electron": "^4.18.0",
"@sentry/hub": "^7.101.1",
Expand Down
146 changes: 119 additions & 27 deletions packages/core/src/bootstrap/tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,36 @@
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
import { OTLPTraceExporter as OTLPTraceExporterGrpc } from '@opentelemetry/exporter-trace-otlp-grpc';
import { NodeSDK } from '@opentelemetry/sdk-node';
import { NodeSDKConfiguration } from '@opentelemetry/sdk-node';
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';
import { NestInstrumentation } from '@opentelemetry/instrumentation-nestjs-core';
import { RedisInstrumentation } from '@opentelemetry/instrumentation-redis';
import { PgInstrumentation } from '@opentelemetry/instrumentation-pg';
import { MySQL2Instrumentation } from '@opentelemetry/instrumentation-mysql2';
import { BatchSpanProcessor, SimpleSpanProcessor, SpanExporter } from '@opentelemetry/sdk-trace-base';
import { HoneycombSDK } from '@honeycombio/opentelemetry-node';
import {
BatchSpanProcessor,
ConsoleSpanExporter,
SimpleSpanProcessor,
SpanExporter
} from '@opentelemetry/sdk-trace-base';
import { HoneycombOptions, HoneycombSDK } from '@honeycombio/opentelemetry-node';
import { diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api';
import { ZipkinExporter } from '@opentelemetry/exporter-zipkin';
import { PeriodicExportingMetricReader, ConsoleMetricExporter } from '@opentelemetry/sdk-metrics';
import { TypeormInstrumentation } from 'opentelemetry-instrumentation-typeorm';
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
import { Resource } from '@opentelemetry/resources';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
// import { PeriodicExportingMetricReader, ConsoleMetricExporter } from '@opentelemetry/sdk-metrics';

let sdk: any;
const isConsole = false; // Set to true to use console exporter only (for debugging)
const isAuto = true; // Set to true to use auto-instrumentations

let provider: NodeTracerProvider;
let honeycombSDK: HoneycombSDK;

let instrumentations: any[];

let traceExporter: SpanExporter;
let url: string;
Expand Down Expand Up @@ -54,6 +70,14 @@ if (process.env.OTEL_ENABLED === 'true') {

console.log('Tracing service name: ' + serviceName);

provider = new NodeTracerProvider({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: serviceName
})
});

provider.register();

url = process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT;

// If OTEL_PROVIDER is not set, use Jaeger by default (as long as OTEL_ENABLED is true of course)
Expand All @@ -77,6 +101,22 @@ if (process.env.OTEL_ENABLED === 'true') {
console.log('Tracing Enabled with Jaeger');
}

if (process.env.OTEL_PROVIDER === 'aspecto') {
if (!url) url = 'https://otelcol.aspecto.io/v1/traces';

const exporterOptions = {
url: url,
serviceName: serviceName,
headers: {
Authorization: process.env.ASPECTO_API_KEY
}
};

traceExporter = new OTLPTraceExporter(exporterOptions);

console.log('Tracing Enabled with Aspecto');
}

if (process.env.OTEL_PROVIDER === 'signoz') {
// Important for Tracing with SigNoz:
// 1. Define env var - OTEL_EXPORTER_OTLP_HEADERS="signoz-access-token=<SIGNOZ_INGESTION_KEY>"
Expand Down Expand Up @@ -140,9 +180,6 @@ if (process.env.OTEL_ENABLED === 'true') {
spanProcessor = new BatchSpanProcessor(traceExporter);
}

const isAuto = true;

let instrumentations: any[];
let instrumentationNames: string[];

if (isAuto) {
Expand All @@ -151,11 +188,22 @@ if (process.env.OTEL_ENABLED === 'true') {
// and expensive during startup
'@opentelemetry/instrumentation-fs': {
enabled: false
},
'@opentelemetry/instrumentation-net': {
enabled: false
},
'@opentelemetry/instrumentation-dns': {
enabled: false
}
});

instrumentations = [autoInst];
instrumentationNames = autoInst.map((i) => i.instrumentationName);

if (process.env.DB_ORM === 'typeorm') {
instrumentations.push(new TypeormInstrumentation());
instrumentationNames.push('TypeormInstrumentation');
}
} else {
const ins = [];
const insNames: string[] = [];
Expand Down Expand Up @@ -184,46 +232,90 @@ if (process.env.OTEL_ENABLED === 'true') {
insNames.push('MySQL2Instrumentation');
}

if (process.env.DB_ORM === 'typeorm') {
ins.push(new TypeormInstrumentation());
insNames.push('TypeormInstrumentation');
}

instrumentations = [ins];
instrumentationNames = insNames;
}

console.log('Tracing Enabled Instrumentations:', instrumentationNames.join(', '));

if (process.env.OTEL_PROVIDER === 'honeycomb') {
/*
const metricReader = new PeriodicExportingMetricReader({
exporter: new ConsoleMetricExporter()
});
*/
if (process.env.HONEYCOMB_API_KEY) {
/*
const metricReader = new PeriodicExportingMetricReader({
exporter: new ConsoleMetricExporter()
});
*/

const params: HoneycombOptions = {
apiKey: process.env.HONEYCOMB_API_KEY,
serviceName: serviceName,
instrumentations: instrumentations,
// metricReader: metricReader,
localVisualizations:
process.env.NODE_ENV === 'development' ||
process.env.HONEYCOMB_ENABLE_LOCAL_VISUALIZATIONS === 'true'
};

if (isConsole) {
params.traceExporter = new ConsoleSpanExporter();
} else {
params.spanProcessor = spanProcessor;
}

sdk = new HoneycombSDK({
apiKey: process.env.HONEYCOMB_API_KEY,
serviceName: serviceName,
spanProcessor: spanProcessor,
instrumentations: instrumentations,
// metricReader: metricReader,
localVisualizations: process.env.NODE_ENV === 'development'
});
honeycombSDK = new HoneycombSDK(params);

console.log('Tracing SDK initialized for Honeycomb');
console.log('Tracing SDK initialized for Honeycomb');
} else {
console.warn('Honeycomb API Key is not set');
}
} else {
/*
const metricReader = new PeriodicExportingMetricReader({
exporter: new ConsoleMetricExporter()
});
*/

sdk = new NodeSDK({
const params: Partial<NodeSDKConfiguration> = {
serviceName: serviceName,
// traceExporter: new ConsoleSpanExporter(),
spanProcessor: spanProcessor,
// metricReader: metricReader,
instrumentations: instrumentations
});
};

if (isConsole) {
params.traceExporter = new ConsoleSpanExporter();
} else {
params.spanProcessor = spanProcessor;
}

provider.addSpanProcessor(spanProcessor);

console.log('Tracing SDK initialized');
}
}

export default sdk;
export default {
start: () => {
if (process.env.OTEL_ENABLED === 'true') {
if (provider) {
registerInstrumentations({
instrumentations: instrumentations
});
}

if (honeycombSDK) {
honeycombSDK.start();
}
}
},
shutdown: () => {
if (process.env.OTEL_ENABLED === 'true') {
provider?.shutdown();
honeycombSDK?.shutdown();
}
}
};
Loading

0 comments on commit 2ecb746

Please sign in to comment.