Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenTelemetry plugin is logging stringified object #169

Open
klippx opened this issue Nov 22, 2024 · 0 comments
Open

OpenTelemetry plugin is logging stringified object #169

klippx opened this issue Nov 22, 2024 · 0 comments

Comments

@klippx
Copy link
Contributor

klippx commented Nov 22, 2024

Sample log:

{
  "level": "error",
  "logger": "OpenTelemetry",
  "message": "{\"message\":\"Request timed out\",\"originalLine\":\"59\",\"originalColumn\":\"25\",\"line\":\"87\",\"column\":\"24\",\"sourceURL\":\"/app/node_modules/@opentelemetry/otlp-exporter-base/build/src/platform/node/http-transport-utils.js\",\"stack\":\"Error: Request timed out\\n    at <anonymous> (/app/node_modules/@opentelemetry/otlp-exporter-base/build/src/platform/node/http-transport-utils.js:87:24)\\n    at emit (node:events:70:22)\\n    at emitCloseNT (node:http:718:33)\\n    at <anonymous> (node:http:1012:70)\\n    at <anonymous> (native:19:28)\\n    at processTicksAndRejections (native:7:39)\",\"name\":\"Error\"}",
  "timestamp": "2024-11-22T14:15:18.780Z"
}

My setup:

const log = winston.createLogger({ ... })

// Need to patch `child` since graphql-mesh uses a non-standard `.child(str: string)` to create log children
const logging = new Proxy(log, {
  get(target, prop, receiver) {
    if (prop === 'child') {
      return (firstArg: string | object, ...args: any[]) => {
        if (typeof firstArg === 'string') {
          return target.child({ logger: firstArg, ...args });
        } else {
          return Reflect.apply(Reflect.get(target, prop, receiver), target, [
            firstArg,
            ...args,
          ]);
        }
      };
    }
    return Reflect.get(target, prop, receiver);
  },
});

export const gatewayConfig = defineConfig({
  logging,
  plugins: (ctx) => [
    useOpenTelemetry({
      ...ctx,
      inheritContext: true, // Optional, whether to inherit the context from the incoming request
      propagateContext: true, // Optional, whether to propagate the context to the outgoing requests
      exporters: [
        createOtelExporter({
          url: `http://${config.OTEL_COLLECTOR_HOST}:${otelPort}`,
        }),
      ],
    }),
  ],
});

and starting with bun hive-gateway supergraph

I can "fix" it by applying a patch commit to the @graphql-mesh/plugin-opentelemetry:

Screenshot 2024-11-22 at 3 13 54 PM

But these patch commits are very tedious to maintain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant