fix(server): OTLP exports say which machine and build they came from (#19370)
Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
e6bbfdb9ff
commit
42da166d13
5 files changed
+38
-4
No files matched your search
@@ -4,6 +4,7 @@ import {
|
||||
makeTraceSink,
|
||||
type SignalExport,
|
||||
} from "@t3tools/shared/observability";
|
||||
import * as HostProcess from "@t3tools/shared/HostProcess";
|
||||
import * as SharedObservability from "@t3tools/shared/observability";
|
||||
import * as OtelEnvironment from "@t3tools/shared/otelEnvironment";
|
||||
import {
|
||||
@@ -625,12 +626,16 @@ const layerTelemetry = Layer.unwrap(
|
||||
Effect.gen(function* () {
|
||||
const environment = yield* DesktopEnvironment.DesktopEnvironment;
|
||||
const endpoints = yield* resolveOtlpEndpoints;
|
||||
// `host.name` keeps machines apart on a shared collector; one set in
|
||||
// `OTEL_RESOURCE_ATTRIBUTES` wins, since explicit attributes override it.
|
||||
const resource = {
|
||||
serviceName: "t3code-desktop",
|
||||
serviceVersion: environment.appVersion,
|
||||
attributes: {
|
||||
"service.namespace": "t3code",
|
||||
"service.runtime": "desktop",
|
||||
"service.mode": environment.isDevelopment ? "development" : "packaged",
|
||||
"host.name": endpoints.resourceAttributes["host.name"] || (yield* HostProcess.Hostname),
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import * as OtelEnvironment from "@t3tools/shared/otelEnvironment";
|
||||
import { assert, describe, it } from "@effect/vitest";
|
||||
|
||||
import * as ServerConfig from "./config.ts";
|
||||
|
||||
describe("otlpResource", () => {
|
||||
const resource = (resourceAttributes: Record<string, string>) =>
|
||||
ServerConfig.otlpResource(
|
||||
{ mode: "web", otelEnvironment: { ...OtelEnvironment.none, resourceAttributes } },
|
||||
"box-1",
|
||||
);
|
||||
|
||||
it("names the host, unless OTEL_RESOURCE_ATTRIBUTES already does", () => {
|
||||
assert.equal(resource({}).attributes["host.name"], "box-1");
|
||||
assert.equal(resource({ "host.name": "from-env" }).attributes["host.name"], "from-env");
|
||||
assert.equal(resource({ "host.name": "" }).attributes["host.name"], "box-1");
|
||||
});
|
||||
});
|
||||
@@ -19,6 +19,7 @@ import * as Schema from "effect/Schema";
|
||||
import { sweepStalePendingAttachments } from "./attachmentStore.ts";
|
||||
import { DEFAULT_SIGNAL_EXPORT, type SignalExport } from "@t3tools/shared/observability";
|
||||
import * as OtelEnvironment from "@t3tools/shared/otelEnvironment";
|
||||
import packageJson from "../package.json" with { type: "json" };
|
||||
|
||||
export const DEFAULT_PORT = 3773;
|
||||
|
||||
@@ -118,14 +119,21 @@ export const make = (config: ServerConfig["Service"]) => ServerConfig.of(config)
|
||||
|
||||
/**
|
||||
* Resource attributes shared by every OTLP exporter, so traces, metrics, and
|
||||
* logs report the same service identity to the collector.
|
||||
* logs report the same service identity to the collector. `host.name` keeps
|
||||
* servers apart when several export to one collector; a `host.name` set in
|
||||
* `OTEL_RESOURCE_ATTRIBUTES` wins, since explicit attributes override it.
|
||||
*/
|
||||
export const otlpResource = (config: ServerConfig["Service"]) => ({
|
||||
export const otlpResource = (
|
||||
config: Pick<ServerConfig["Service"], "mode" | "otelEnvironment">,
|
||||
hostName: string,
|
||||
) => ({
|
||||
serviceName: "t3code-server",
|
||||
serviceVersion: packageJson.version,
|
||||
attributes: {
|
||||
"service.namespace": "t3code",
|
||||
"service.runtime": "t3-server",
|
||||
"service.mode": config.mode,
|
||||
"host.name": config.otelEnvironment.resourceAttributes["host.name"] || hostName,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import * as HostProcess from "@t3tools/shared/HostProcess";
|
||||
import * as HttpObservability from "@t3tools/shared/httpObservability";
|
||||
import { makeLocalFileTracer, makeTraceSink } from "@t3tools/shared/observability";
|
||||
import * as SharedObservability from "@t3tools/shared/observability";
|
||||
@@ -25,7 +26,7 @@ export const layer = Layer.unwrap(
|
||||
// The trace serializer stays in the returned context because the browser
|
||||
// trace forwarder exports on the same signal.
|
||||
const layerSerialization = SharedObservability.layerOtlpSerialization(traces.protocol);
|
||||
const resource = ServerConfig.otlpResource(config);
|
||||
const resource = ServerConfig.otlpResource(config, yield* HostProcess.Hostname);
|
||||
const attribution = yield* ResourceAttribution.ResourceAttribution;
|
||||
|
||||
const layerTraceReferences = Layer.mergeAll(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import * as HostProcess from "@t3tools/shared/HostProcess";
|
||||
import * as SharedObservability from "@t3tools/shared/observability";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Layer from "effect/Layer";
|
||||
@@ -10,6 +11,7 @@ import * as ServerConfig from "./config.ts";
|
||||
|
||||
export const layer = Effect.gen(function* () {
|
||||
const config = yield* ServerConfig.ServerConfig;
|
||||
const hostName = yield* HostProcess.Hostname;
|
||||
const layerMinimumLogLevel = Layer.succeed(References.MinimumLogLevel, config.logLevel);
|
||||
|
||||
const logs = config.otlpLogsExport;
|
||||
@@ -20,7 +22,7 @@ export const layer = Effect.gen(function* () {
|
||||
url: config.otlpLogsUrl,
|
||||
exportInterval: `${logs.exportIntervalMs} millis`,
|
||||
headers: logs.headers,
|
||||
resource: ServerConfig.otlpResource(config),
|
||||
resource: ServerConfig.otlpResource(config, hostName),
|
||||
});
|
||||
|
||||
// `Logger.layer` writes the whole logger set rather than adding to it, so
|
||||
|
||||
Reference in new issue
Block a user