solarwinds-apm
Version:
OpenTelemetry-based SolarWinds APM library
53 lines (43 loc) • 1.75 kB
text/typescript
/*
Copyright 2023-2025 SolarWinds Worldwide, LLC.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import { type OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-proto"
import { type OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-proto"
import { type OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto"
import { CompressionAlgorithm } from "@opentelemetry/otlp-exporter-base"
import { type Configuration } from "../shared/config.js"
type Options<Exporter extends new (options: never) => unknown> =
Exporter extends new (options: infer Options) => unknown ? Options : never
export function exporterConfig(
config: Configuration & { trustedpath?: string },
signal: "traces" | "metrics" | "logs",
): Options<
typeof OTLPTraceExporter | typeof OTLPMetricExporter | typeof OTLPLogExporter
> {
const url = config.otlp[signal]
const headers = { ...config.headers }
try {
if (config.token && new URL(url).hostname.endsWith(".solarwinds.com")) {
headers.authorization = `Bearer ${config.token}`
}
} catch {
// invalid user provided endpoint url
}
return {
url,
headers,
compression: CompressionAlgorithm.GZIP,
httpAgentOptions: {
ca: config.trustedpath,
},
}
}