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

[Beta] - "ApplicationInsights:Invalid attribute value set for key: req []" #1168

Open
marcus13371337 opened this issue Jul 3, 2023 · 3 comments

Comments

@marcus13371337
Copy link

marcus13371337 commented Jul 3, 2023

Hello,

I just bumped to 3.0.0-beta.6 (from 3.0.0-beta.4) and started noticing a lot of errors in my application:

ApplicationInsights:Invalid attribute value set for key: req []
ApplicationInsights:Invalid attribute value set for key: res []

What's up with that? Am I doing something wrong?

@hectorhdzg
Copy link
Member

hectorhdzg commented Jul 3, 2023

@marcus13371337 can you share the actual telemetry event that is triggering this?, I can see there is some OpenTelemetry that add the warning when the value of the attribute is null, you may want to sanitize the attributes before sending the telemetry

@marcus13371337
Copy link
Author

@hectorhdzg I can't reproduce it locally unfortunately. However, it seems as if objects and errors are sent with toString instead of JSON-serialized (which worked in the earlier version).
Screenshot 2023-07-04 at 08 28 29

I think it's an error on our side, we have a logging to trace converter which was implemented this way:

  const getLogProperties = (entry: LogEntry) => {
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    const { msg, ...rest } = entry;

    return {
      ...rest,
    };
  };

  const insertTrace = (entry: LogEntry) => {
    const inserts: Promise<void>[] = [];

    inserts.push(
      logHandler.trackTrace({
        message: entry.msg,
        severity: getLogSeverityName(entry.level),
        properties: getLogProperties(entry),
      })
    );

    if (entry.level >= 50) {
      const err = new Error(entry.msg);
      err.stack = entry.stack || "";

      inserts.push(
        logHandler.trackException({
          exception: err,
          properties: getLogProperties(entry),
        })
      );
    }

    return Promise.all(inserts);
  };

We had to fix that with the following change:

  const getLogProperties = (entry: LogEntry) => {
    const { msg, ...rest } = entry;

    return Object.entries(rest).reduce(
      (acc, [key, value]) => ({ ...acc, [key]: JSON.stringify(value) }), // Apperently you need to JSON-stringify in the new version
      {}
    );
  };

  const insertTrace = (entry: LogEntry) => {
    const inserts: Promise<void>[] = [];

    inserts.push(
      logHandler.trackTrace({
        message: entry.msg,
        severity: getLogSeverityName(entry.level),
        properties: getLogProperties(entry),
      })
    );

    if (entry.level >= 50) {
      const err = new Error(entry.msg);
      err.stack = entry.stack || "";

      inserts.push(
        logHandler.trackException({
          exception: err,
          properties: getLogProperties(entry),
        })
      );
    }

    return Promise.all(inserts);
  };

Note the difference in getLogProperties. I'm not sure if it's a bug or a feature :)

@marcus13371337
Copy link
Author

marcus13371337 commented Jul 4, 2023

The fix above fixed the issue reported in the logs i.e "ApplicationInsights:Invalid attribute value set for key: req"

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

2 participants