feat: allow all NodeSDK options via registerOtel (#11460)
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
feat: allow all NodeSDK options via registerOtel
|
||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
import { ApiRoutesLoader } from "@medusajs/framework/http"
|
import { ApiRoutesLoader } from "@medusajs/framework/http"
|
||||||
import { Tracer } from "@medusajs/framework/telemetry"
|
import { Tracer } from "@medusajs/framework/telemetry"
|
||||||
import type { SpanExporter } from "@opentelemetry/sdk-trace-node"
|
import type { SpanExporter } from "@opentelemetry/sdk-trace-node"
|
||||||
import type { Instrumentation } from "@opentelemetry/instrumentation"
|
import type { NodeSDKConfiguration } from "@opentelemetry/sdk-node"
|
||||||
import { TransactionOrchestrator } from "@medusajs/framework/orchestration"
|
import { TransactionOrchestrator } from "@medusajs/framework/orchestration"
|
||||||
|
|
||||||
const EXCLUDED_RESOURCES = [".vite", "virtual:"]
|
const EXCLUDED_RESOURCES = [".vite", "virtual:"]
|
||||||
@@ -270,24 +270,34 @@ export function instrumentWorkflows() {
|
|||||||
* - @opentelemetry/instrumentation-pg
|
* - @opentelemetry/instrumentation-pg
|
||||||
* - @opentelemetry/instrumentation
|
* - @opentelemetry/instrumentation
|
||||||
*/
|
*/
|
||||||
export function registerOtel(options: {
|
export function registerOtel(
|
||||||
serviceName: string
|
options: Partial<NodeSDKConfiguration> & {
|
||||||
exporter: SpanExporter
|
serviceName: string
|
||||||
instrument?: Partial<{
|
exporter?: SpanExporter
|
||||||
http: boolean
|
instrument?: Partial<{
|
||||||
query: boolean
|
http: boolean
|
||||||
workflows: boolean
|
query: boolean
|
||||||
db: boolean
|
workflows: boolean
|
||||||
}>
|
db: boolean
|
||||||
instrumentations?: Instrumentation[]
|
}>
|
||||||
}) {
|
}
|
||||||
|
) {
|
||||||
|
const {
|
||||||
|
exporter,
|
||||||
|
serviceName,
|
||||||
|
instrument,
|
||||||
|
instrumentations,
|
||||||
|
...nodeSdkOptions
|
||||||
|
} = {
|
||||||
|
instrument: {},
|
||||||
|
instrumentations: [],
|
||||||
|
...options,
|
||||||
|
}
|
||||||
|
|
||||||
const { Resource } = require("@opentelemetry/resources")
|
const { Resource } = require("@opentelemetry/resources")
|
||||||
const { NodeSDK } = require("@opentelemetry/sdk-node")
|
const { NodeSDK } = require("@opentelemetry/sdk-node")
|
||||||
const { SimpleSpanProcessor } = require("@opentelemetry/sdk-trace-node")
|
const { SimpleSpanProcessor } = require("@opentelemetry/sdk-trace-node")
|
||||||
|
|
||||||
const instrument = options.instrument || {}
|
|
||||||
const instrumentations = options.instrumentations || []
|
|
||||||
|
|
||||||
if (instrument.db) {
|
if (instrument.db) {
|
||||||
const { PgInstrumentation } = require("@opentelemetry/instrumentation-pg")
|
const { PgInstrumentation } = require("@opentelemetry/instrumentation-pg")
|
||||||
instrumentations.push(new PgInstrumentation())
|
instrumentations.push(new PgInstrumentation())
|
||||||
@@ -303,13 +313,12 @@ export function registerOtel(options: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const sdk = new NodeSDK({
|
const sdk = new NodeSDK({
|
||||||
serviceName: options.serviceName,
|
serviceName,
|
||||||
resource: new Resource({
|
resource: new Resource({ "service.name": serviceName }),
|
||||||
"service.name": options.serviceName,
|
spanProcessor: new SimpleSpanProcessor(exporter),
|
||||||
}),
|
...nodeSdkOptions,
|
||||||
spanProcessor: new SimpleSpanProcessor(options.exporter),
|
|
||||||
instrumentations: instrumentations,
|
instrumentations: instrumentations,
|
||||||
})
|
} satisfies Partial<NodeSDKConfiguration>)
|
||||||
|
|
||||||
sdk.start()
|
sdk.start()
|
||||||
return sdk
|
return sdk
|
||||||
|
|||||||
Reference in New Issue
Block a user