-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: otel collector integration (#4769)
* chore: WIP for an otel-collector provider * feat: create exporter that can be configured at a later point and then exports spans * feat: send traces to OTLP exporter once collector is spawned * feat: wait for initialization of collector * chore: remove redundant createModuleTypes * feat: create temporary config if it does not exist * wip: start creating config for datadog * feat: ensure that async hooks are run when the process is shut down * feat: log logged processes output with silly loglevel * feat: ensure collector has enough time to terminate * feat: wait for datadog export log line explicitly * refactor: simplify config generation and get actual hostname * feat: make datadog configurable from the API secrets * feat: support multiple concurrent http exporters, refactor config * refactor: extract out base config * feat: trace the otel collector startup times * feat: configure exporters in provider config * feat: timeout for final datadog sync * feat: wait for collector process to terminate * feat: add honeycomb support * fix: bind to localhost, handle empty exporters * fix: otel provider example and added the logging exporter * chore: remove unused import * fix: work around anyOf validation to schema conversion Should receive the same follow up fix as `oneOf` * fix: license headers * chore: code formatting * docs: update docs * chore: remove two todos * chore: remove projectId from plugin context * refactor: move validators into exporter modules and use those for the config types * feat: always enable tracing by default but no-op when it's not configured * fix: remove console.log statements * feat: address review comments * fix: make sure when there are no active otel exporters the no-op exporter is used * test: e2e smoke test for otel exporter * fix: correct hostname for test * fix: explicitly forward log events from provider instead of having `streamLogs` do it implicitly --------- Co-authored-by: Mikael Hoegqvist Tabor <[email protected]>
- Loading branch information
Showing
68 changed files
with
4,544 additions
and
116 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
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
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
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
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
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
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,74 @@ | ||
/* | ||
* Copyright (C) 2018-2023 Garden Technologies, Inc. <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { mergeWith } from "lodash" | ||
import { MergeDeep } from "type-fest" | ||
import { | ||
OtlpHttpExporterConfigPartial, | ||
OtelCollectorOtlpHttpConfiguration, | ||
makeOtlpHttpPartialConfig, | ||
} from "./config/otlphttp" | ||
import { | ||
DatadogExporterConfigPartial, | ||
OtelCollectorDatadogConfiguration, | ||
makeDatadogPartialConfig, | ||
} from "./config/datadog" | ||
import { OtelCollectorNewRelicConfiguration, makeNewRelicPartialConfig } from "./config/newrelic" | ||
import { OtelCollectorBaseConfig, getOtelCollectorBaseConfig } from "./config/base" | ||
import { OtelCollectorHoneycombConfiguration, makeHoneycombPartialConfig } from "./config/honeycomb" | ||
import { OtelCollectorLoggingConfiguration, makeLoggingPartialConfig } from "./config/logging" | ||
|
||
export type OtelConfigFile = MergeDeep< | ||
OtelCollectorBaseConfig, | ||
MergeDeep<OtlpHttpExporterConfigPartial, DatadogExporterConfigPartial, { arrayMergeMode: "spread" }>, | ||
{ arrayMergeMode: "spread" } | ||
> | ||
|
||
export type OtelExportersConfig = | ||
| OtelCollectorLoggingConfiguration | ||
| OtelCollectorDatadogConfiguration | ||
| OtelCollectorNewRelicConfiguration | ||
| OtelCollectorOtlpHttpConfiguration | ||
| OtelCollectorHoneycombConfiguration | ||
|
||
export type OtelCollectorConfigFileOptions = { | ||
exporters: OtelExportersConfig[] | ||
} | ||
|
||
function mergeArrays(objValue, srcValue) { | ||
if (Array.isArray(objValue)) { | ||
return objValue.concat(srcValue) | ||
} | ||
return undefined | ||
} | ||
|
||
export function getOtelCollectorConfigFile({ exporters }: OtelCollectorConfigFileOptions) { | ||
let config: OtelConfigFile = getOtelCollectorBaseConfig() | ||
|
||
for (const exporter of exporters) { | ||
if (exporter.enabled) { | ||
if (exporter.name === "datadog") { | ||
config = mergeWith(config, makeDatadogPartialConfig(exporter), mergeArrays) | ||
} | ||
if (exporter.name === "newrelic") { | ||
config = mergeWith(config, makeNewRelicPartialConfig(exporter), mergeArrays) | ||
} | ||
if (exporter.name === "otlphttp") { | ||
config = mergeWith(config, makeOtlpHttpPartialConfig(exporter), mergeArrays) | ||
} | ||
if (exporter.name === "honeycomb") { | ||
config = mergeWith(config, makeHoneycombPartialConfig(exporter), mergeArrays) | ||
} | ||
if (exporter.name === "logging") { | ||
config = mergeWith(config, makeLoggingPartialConfig(exporter), mergeArrays) | ||
} | ||
} | ||
} | ||
|
||
return config | ||
} |
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,71 @@ | ||
/* | ||
* Copyright (C) 2018-2023 Garden Technologies, Inc. <[email protected]> | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
import { sdk } from "../../../plugin/sdk" | ||
|
||
const s = sdk.schema | ||
|
||
export const baseValidator = s.object({ | ||
name: s.string(), | ||
enabled: s.boolean(), | ||
}) | ||
|
||
export type OtelCollectorBaseConfig = { | ||
processors: { | ||
batch: null | { | ||
send_batch_max_size?: number | ||
timeout?: string | ||
} | ||
} | ||
exporters: {} | ||
extensions: Record<string, null> | ||
service: { | ||
extensions: string[] | ||
pipelines: { | ||
traces: { | ||
receivers: ["otlp"] | ||
processors: ["batch"] | ||
exporters: string[] | ||
} | ||
} | ||
telemetry: { | ||
logs: { | ||
level: string | ||
} | ||
} | ||
} | ||
} | ||
|
||
export function getOtelCollectorBaseConfig(): OtelCollectorBaseConfig { | ||
return { | ||
processors: { | ||
batch: null, | ||
}, | ||
exporters: {}, | ||
extensions: { | ||
health_check: null, | ||
pprof: null, | ||
zpages: null, | ||
}, | ||
service: { | ||
extensions: [], | ||
pipelines: { | ||
traces: { | ||
receivers: ["otlp"], | ||
processors: ["batch"], | ||
exporters: [], | ||
}, | ||
}, | ||
telemetry: { | ||
logs: { | ||
level: "debug", | ||
}, | ||
}, | ||
}, | ||
} | ||
} |
Oops, something went wrong.