Add OpenTelemetry OTLP HTTP exporter and headers

This commit is contained in:
Simon Larsen 2024-02-23 12:47:14 +00:00
parent bc47842e35
commit 7ced477ec9
No known key found for this signature in database
GPG Key ID: AB45983AA9C81CDE
6 changed files with 174 additions and 13 deletions

View File

@ -13,6 +13,7 @@
"@opentelemetry/api": "^1.7.0",
"@opentelemetry/auto-instrumentations-web": "^0.36.0",
"@opentelemetry/context-zone": "^1.21.0",
"@opentelemetry/exporter-trace-otlp-http": "^0.48.0",
"@opentelemetry/resources": "^1.21.0",
"@opentelemetry/sdk-trace-web": "^1.21.0",
"@opentelemetry/semantic-conventions": "^1.21.0",
@ -1295,6 +1296,17 @@
"node": ">=8.0.0"
}
},
"node_modules/@opentelemetry/api-logs": {
"version": "0.48.0",
"resolved": "https://registry.npmjs.org/@opentelemetry/api-logs/-/api-logs-0.48.0.tgz",
"integrity": "sha512-1/aMiU4Eqo3Zzpfwu51uXssp5pzvHFObk8S9pKAiXb1ne8pvg1qxBQitYL1XUiAMEXFzgjaidYG2V6624DRhhw==",
"dependencies": {
"@opentelemetry/api": "^1.0.0"
},
"engines": {
"node": ">=14"
}
},
"node_modules/@opentelemetry/auto-instrumentations-web": {
"version": "0.36.0",
"resolved": "https://registry.npmjs.org/@opentelemetry/auto-instrumentations-web/-/auto-instrumentations-web-0.36.0.tgz",
@ -1352,6 +1364,24 @@
"@opentelemetry/api": ">=1.0.0 <1.8.0"
}
},
"node_modules/@opentelemetry/exporter-trace-otlp-http": {
"version": "0.48.0",
"resolved": "https://registry.npmjs.org/@opentelemetry/exporter-trace-otlp-http/-/exporter-trace-otlp-http-0.48.0.tgz",
"integrity": "sha512-QEZKbfWqXrbKVpr2PHd4KyKI0XVOhUYC+p2RPV8s+2K5QzZBE3+F9WlxxrXDfkrvGmpQAZytBoHQQYA3AGOtpw==",
"dependencies": {
"@opentelemetry/core": "1.21.0",
"@opentelemetry/otlp-exporter-base": "0.48.0",
"@opentelemetry/otlp-transformer": "0.48.0",
"@opentelemetry/resources": "1.21.0",
"@opentelemetry/sdk-trace-base": "1.21.0"
},
"engines": {
"node": ">=14"
},
"peerDependencies": {
"@opentelemetry/api": "^1.0.0"
}
},
"node_modules/@opentelemetry/instrumentation": {
"version": "0.48.0",
"resolved": "https://registry.npmjs.org/@opentelemetry/instrumentation/-/instrumentation-0.48.0.tgz",
@ -1469,6 +1499,39 @@
"resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz",
"integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A=="
},
"node_modules/@opentelemetry/otlp-exporter-base": {
"version": "0.48.0",
"resolved": "https://registry.npmjs.org/@opentelemetry/otlp-exporter-base/-/otlp-exporter-base-0.48.0.tgz",
"integrity": "sha512-T4LJND+Ugl87GUONoyoQzuV9qCn4BFIPOnCH1biYqdGhc2JahjuLqVD9aefwLzGBW638iLAo88Lh68h2F1FLiA==",
"dependencies": {
"@opentelemetry/core": "1.21.0"
},
"engines": {
"node": ">=14"
},
"peerDependencies": {
"@opentelemetry/api": "^1.0.0"
}
},
"node_modules/@opentelemetry/otlp-transformer": {
"version": "0.48.0",
"resolved": "https://registry.npmjs.org/@opentelemetry/otlp-transformer/-/otlp-transformer-0.48.0.tgz",
"integrity": "sha512-yuoS4cUumaTK/hhxW3JUy3wl2U4keMo01cFDrUOmjloAdSSXvv1zyQ920IIH4lymp5Xd21Dj2/jq2LOro56TJg==",
"dependencies": {
"@opentelemetry/api-logs": "0.48.0",
"@opentelemetry/core": "1.21.0",
"@opentelemetry/resources": "1.21.0",
"@opentelemetry/sdk-logs": "0.48.0",
"@opentelemetry/sdk-metrics": "1.21.0",
"@opentelemetry/sdk-trace-base": "1.21.0"
},
"engines": {
"node": ">=14"
},
"peerDependencies": {
"@opentelemetry/api": ">=1.3.0 <1.8.0"
}
},
"node_modules/@opentelemetry/resources": {
"version": "1.21.0",
"resolved": "https://registry.npmjs.org/@opentelemetry/resources/-/resources-1.21.0.tgz",
@ -1484,6 +1547,38 @@
"@opentelemetry/api": ">=1.0.0 <1.8.0"
}
},
"node_modules/@opentelemetry/sdk-logs": {
"version": "0.48.0",
"resolved": "https://registry.npmjs.org/@opentelemetry/sdk-logs/-/sdk-logs-0.48.0.tgz",
"integrity": "sha512-lRcA5/qkSJuSh4ItWCddhdn/nNbVvnzM+cm9Fg1xpZUeTeozjJDBcHnmeKoOaWRnrGYBdz6UTY6bynZR9aBeAA==",
"dependencies": {
"@opentelemetry/core": "1.21.0",
"@opentelemetry/resources": "1.21.0"
},
"engines": {
"node": ">=14"
},
"peerDependencies": {
"@opentelemetry/api": ">=1.4.0 <1.8.0",
"@opentelemetry/api-logs": ">=0.39.1"
}
},
"node_modules/@opentelemetry/sdk-metrics": {
"version": "1.21.0",
"resolved": "https://registry.npmjs.org/@opentelemetry/sdk-metrics/-/sdk-metrics-1.21.0.tgz",
"integrity": "sha512-on1jTzIHc5DyWhRP+xpf+zrgrREXcHBH4EDAfaB5mIG7TWpKxNXooQ1JCylaPsswZUv4wGnVTinr4HrBdGARAQ==",
"dependencies": {
"@opentelemetry/core": "1.21.0",
"@opentelemetry/resources": "1.21.0",
"lodash.merge": "^4.6.2"
},
"engines": {
"node": ">=14"
},
"peerDependencies": {
"@opentelemetry/api": ">=1.3.0 <1.8.0"
}
},
"node_modules/@opentelemetry/sdk-trace-base": {
"version": "1.21.0",
"resolved": "https://registry.npmjs.org/@opentelemetry/sdk-trace-base/-/sdk-trace-base-1.21.0.tgz",
@ -5734,6 +5829,11 @@
"integrity": "sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag==",
"dev": true
},
"node_modules/lodash.merge": {
"version": "4.6.2",
"resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz",
"integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ=="
},
"node_modules/longest-streak": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/longest-streak/-/longest-streak-3.1.0.tgz",

View File

@ -18,6 +18,7 @@
"@opentelemetry/api": "^1.7.0",
"@opentelemetry/auto-instrumentations-web": "^0.36.0",
"@opentelemetry/context-zone": "^1.21.0",
"@opentelemetry/exporter-trace-otlp-http": "^0.48.0",
"@opentelemetry/resources": "^1.21.0",
"@opentelemetry/sdk-trace-web": "^1.21.0",
"@opentelemetry/semantic-conventions": "^1.21.0",

View File

@ -20,6 +20,7 @@ import Version from 'Common/Types/Version';
import URL from 'Common/Types/API/URL';
import SubscriptionPlan from 'Common/Types/Billing/SubscriptionPlan';
import { JSONObject } from 'Common/Types/JSON';
import Dictionary from 'Common/Types/Dictionary';
export const getAllEnvVars: Function = (): JSONObject => {
const envVars: JSONObject = window?.process?.env || process?.env || {};
@ -155,3 +156,29 @@ export const AnalyticsHost: string = env('ANALYTICS_HOST');
export const GitSha: string = env('GIT_SHA') || '';
export const AppVersion: string = env('APP_VERSION') || '';
export const OpenTelemetryExporterOtlpEndpoint = env('OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT') ? URL.fromString(env('OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT').toString()) : null;
const getOpenTelemetryExporterOtlpHeaders: Function = (): Dictionary<string> => {
if (!env('OPENTELEMETRY_EXPORTER_OTLP_HEADERS')) {
return {};
}
const headersStrings: Array<string> =
env('OPENTELEMETRY_EXPORTER_OTLP_HEADERS').toString().split(';');
const headers: Dictionary<string> = {};
for (const headerString of headersStrings) {
const header: Array<string> = headerString.split('=');
if (header.length === 2) {
headers[header[0]!.toString()] = header[1]!.toString();
}
}
return headers;
}
export const OpenTelemetryExporterOtlpHeaders: Dictionary<string> = getOpenTelemetryExporterOtlpHeaders();

View File

@ -1,9 +1,15 @@
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { getWebAutoInstrumentations } from '@opentelemetry/auto-instrumentations-web';
import { ConsoleSpanExporter, SimpleSpanProcessor, TracerConfig, WebTracerProvider } from '@opentelemetry/sdk-trace-web';
import {
BatchSpanProcessor,
TracerConfig,
WebTracerProvider,
} from '@opentelemetry/sdk-trace-web';
import { ZoneContextManager } from '@opentelemetry/context-zone';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { Resource } from '@opentelemetry/resources';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
import { OpenTelemetryExporterOtlpEndpoint, OpenTelemetryExporterOtlpHeaders } from '../Config';
const providerConfig: TracerConfig = {
resource: new Resource({
@ -14,7 +20,17 @@ const providerConfig: TracerConfig = {
const provider = new WebTracerProvider(providerConfig);
// we will use ConsoleSpanExporter to check the generated spans in dev console
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
// provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
if (OpenTelemetryExporterOtlpEndpoint) {
provider.addSpanProcessor(
new BatchSpanProcessor(new OTLPTraceExporter({
url: OpenTelemetryExporterOtlpEndpoint?.toString(),
headers: OpenTelemetryExporterOtlpHeaders
})),
);
}
provider.register({
contextManager: new ZoneContextManager(),
@ -26,8 +42,8 @@ registerInstrumentations({
// it's possible to configure each instrumentation if needed.
getWebAutoInstrumentations({
'@opentelemetry/instrumentation-fetch': {
enabled: true
enabled: true,
},
}),
],
});
});

View File

@ -170,12 +170,20 @@ BILLING_PRIVATE_KEY=
# Use this when you want to disable incident creation.
DISABLE_AUTOMATIC_INCIDENT_CREATION=false
# If you're using an extrenal open telemetry collector, you can set the endpoint here - both server and client endpoint can be the same in this case.
# You can set the env var to http://otel-collector:4318 if you want instrumentation to be sent to otel collector.
OTEL_EXPORTER_OTLP_ENDPOINT=
SERVER_OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT=
# You can set the env var to http://localhost/otlp if you want instrumentation to be sent to local otel collector.
CLIENT_OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT=
# You can set the env var to "x-oneuptime-service-token=<YOUR_ONEUPTIME_SERVICE_TOKEN>"
APP_OTEL_EXPORTER_OTLP_HEADERS=
PROBE_OTEL_EXPORTER_OTLP_HEADERS=
APP_OPENTELEMETRY_EXPORTER_OTLP_HEADERS=
PROBE_OPENTELEMETRY_EXPORTER_OTLP_HEADERS=
DASHBOARD_OPENTELEMETRY_EXPORTER_OTLP_HEADERS=
STATUS_PAGE_OPENTELEMETRY_EXPORTER_OTLP_HEADERS=
ACCOUNTS_OPENTELEMETRY_EXPORTER_OTLP_HEADERS=
ADMIN_DASHBOARD_OPENTELEMETRY_EXPORTER_OTLP_HEADERS=

View File

@ -158,6 +158,9 @@ services:
environment:
<<: *common-ui-variables
PORT: ${ACCOUNTS_PORT}
OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT: ${CLIENT_OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT}
OPENTELEMETRY_EXPORTER_OTLP_HEADERS: ${ACCOUNTS_OPENTELEMETRY_EXPORTER_OTLP_HEADERS}
logging:
driver: "local"
options:
@ -171,6 +174,8 @@ services:
environment:
<<: *common-ui-variables
PORT: ${ADMIN_DASHBOARD_PORT}
OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT: ${CLIENT_OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT}
OPENTELEMETRY_EXPORTER_OTLP_HEADERS: ${ADMIN_DASHBOARD_OPENTELEMETRY_EXPORTER_OTLP_HEADERS}
logging:
driver: "local"
options:
@ -183,6 +188,8 @@ services:
environment:
<<: *common-ui-variables
PORT: ${DASHBOARD_PORT}
OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT: ${CLIENT_OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT}
OPENTELEMETRY_EXPORTER_OTLP_HEADERS: ${DASHBOARD_OPENTELEMETRY_EXPORTER_OTLP_HEADERS}
logging:
driver: "local"
options:
@ -197,6 +204,8 @@ services:
environment:
<<: *common-ui-variables
PORT: ${STATUS_PAGE_PORT}
OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT: ${CLIENT_OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT}
OPENTELEMETRY_EXPORTER_OTLP_HEADERS: ${STATUS_PAGE_OPENTELEMETRY_EXPORTER_OTLP_HEADERS}
logging:
driver: "local"
options:
@ -231,8 +240,8 @@ services:
INTERNAL_SMTP_EMAIL: ${INTERNAL_SMTP_EMAIL}
INTERNAL_SMTP_FROM_NAME: ${INTERNAL_SMTP_FROM_NAME}
INTERNAL_SMTP_PASSWORD: ${INTERNAL_SMTP_PASSWORD}
OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT}
OPENTELEMETRY_EXPORTER_OTLP_HEADERS: ${APP_OTEL_EXPORTER_OTLP_HEADERS}
OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT: ${SERVER_OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT}
OPENTELEMETRY_EXPORTER_OTLP_HEADERS: ${APP_OPENTELEMETRY_EXPORTER_OTLP_HEADERS}
logging:
driver: "local"
options:
@ -252,8 +261,8 @@ services:
PROBE_KEY: ${GLOBAL_PROBE_1_KEY}
ONEUPTIME_URL: ${GLOBAL_PROBE_1_ONEUPTIME_URL}
PROBE_MONITOR_FETCH_LIMIT: ${GLOBAL_PROBE_1_MONITOR_FETCH_LIMIT}
OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT}
OTEL_EXPORTER_OTLP_HEADERS: ${PROBE_OTEL_EXPORTER_OTLP_HEADERS}
OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT: ${SERVER_OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT}
OPENTELEMETRY_EXPORTER_OTLP_HEADERS: ${PROBE_OPENTELEMETRY_EXPORTER_OTLP_HEADERS}
logging:
driver: "local"
options:
@ -272,8 +281,8 @@ services:
PROBE_KEY: ${GLOBAL_PROBE_2_KEY}
ONEUPTIME_URL: ${GLOBAL_PROBE_2_ONEUPTIME_URL}
PROBE_MONITOR_FETCH_LIMIT: ${GLOBAL_PROBE_2_MONITOR_FETCH_LIMIT}
OTEL_EXPORTER_OTLP_ENDPOINT: ${OTEL_EXPORTER_OTLP_ENDPOINT}
OTEL_EXPORTER_OTLP_HEADERS: ${PROBE_OTEL_EXPORTER_OTLP_HEADERS}
OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT: ${SERVER_OPENTELEMETRY_EXPORTER_OTLP_ENDPOINT}
OPENTELEMETRY_EXPORTER_OTLP_HEADERS: ${PROBE_OPENTELEMETRY_EXPORTER_OTLP_HEADERS}
logging:
driver: "local"
options: