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

Default Context not being attached to logs. per documentation #74

Open
BryantDavis1986 opened this issue Aug 25, 2024 · 8 comments
Open

Comments

@BryantDavis1986
Copy link

Issue Report: LogDNA Browser Logging

Description

There is an issue with the logging mechanism in the LogDNA browser integration. The logs occasionally fail to capture the default context, including location, user information, environment, etc.

Example Log

image

LogDNA Initialization Code

const hostname = 'Tradeweb-User-Interface';
logdna.init(CONFIG.logDnaApiKey, {
  app: `Tradeweb-User-Interface`,
  env: CONFIG.env,
  hostname: hostname,
  enableStacktrace: true,
  enableIpAddress: true,
  console: CONFIG.logDnaEnabledLocally
});
if (CONFIG.logDnaEnabledLocally) {
  console.log = (message, ...optionalParams) => logdna.log({ message: chalk.green(message, JSON.stringify(optionalParams)) });
  console.error = (message, ...optionalParams) => logdna.error({ message: chalk.red(message, JSON.stringify(optionalParams)) });
  console.debug = (message, ...optionalParams) => logdna.debug({ message: chalk.blue(message, JSON.stringify(optionalParams)) });
  console.warn = (message, ...optionalParams) => logdna.warn({ message: chalk.yellow(message, JSON.stringify(optionalParams))});
  console.info = (message, ...optionalParams) => logdna.info({ message: chalk.cyan(message, JSON.stringify(optionalParams))});
}

Automatically Added Context (from documentation)

"sessionId": "d1b69ea3-41c4-4b9b-85e2-32fb94cb219c",
"browser": {
  "name": "chrome",
  "version": "87.0.4280",
  "os": "Mac OS",
  "type": "browser"
},
"location": {
  "ancestorOrigins": {},
  "href": "https://your-web-app/home?q=1234567890",
  "origin": "https://your-web-app",
  "protocol": "https:",
  "host": "your-web-app",
  "hostname": "your-web-app",
  "port": "",
  "pathname": "/home",
  "search": "?q=1234567890",
  "hash": ""
}

Expected Behavior

The logs should consistently capture the default context, including location, user information, environment, etc.

@TerryMooreII
Copy link
Collaborator

Looking at the message in the screen shot, it appears that this isnt an issue with the context not being captured but the line parser not being able to parse the data. Here is more information https://docs.mezmo.com/docs/log-parsing

@BryantDavis1986
Copy link
Author

Looking at the message in the screen shot, it appears that this isnt an issue with the context not being captured but the line parser not being able to parse the data. Here is more information https://docs.mezmo.com/docs/log-parsing

yes it is a parsing error. i have tested removing the optional params, my additional context for user. it seems since i am not providing any additional meta data or context i still receive this error from the default context provided by the package.

@BryantDavis1986
Copy link
Author

Looking at the message in the screen shot, it appears that this isnt an issue with the context not being captured but the line parser not being able to parse the data. Here is more information https://docs.mezmo.com/docs/log-parsing

this was the context i was attempting to use:
image

i tried varying variable name from userName, userEmail etc they all seem to fail even though all the values are always strings.
i attempted to follow the docs which show this:
image
which shows the ability to add an object for user. but when i attempt to do so their is a type error from the package:
image

where the calues must be of type ContextT:
image

this is me logging my context object in logdna:
image
in browser console:
image

the code doing the logging:
image

everything is consistently strings. so it is unclear to me the current issue with parsing.

no additional context provided by my app with the add context useEffect commented out:
image

@TerryMooreII
Copy link
Collaborator

If you look at the first screen shot, it appears that you are attempting to add the string "(app=Tradeweb-User-Interface, userEmail=cypress-buyer@alphaledger.com, env=ga, userName=Cypres Underwriter) " to the meta.context but meta.context expects an object and there is unable to parse it.
The indexer will reset ever 24 hours or so but during that time the data types should not change. So if the first log that come through provides the meta.context as an object then the rest of the lines should be the same or if meta.context first got set as a string the every other time meta.context should be a string until it resets.

@BryantDavis1986
Copy link
Author

If you look at the first screen shot, it appears that you are attempting to add the string "(app=Tradeweb-User-Interface, userEmail=cypress-buyer@alphaledger.com, env=ga, userName=Cypres Underwriter) " to the meta.context but meta.context expects an object and there is unable to parse it. The indexer will reset ever 24 hours or so but during that time the data types should not change. So if the first log that come through provides the meta.context as an object then the rest of the lines should be the same or if meta.context first got set as a string the every other time meta.context should be a string until it resets.

so i have waited over 24hrs. saw the logs and the context work but then it stops. I am unsure how more consistent i can be with the context i am adding to always be strings. is the app wide issue? so if the issue is happening inconsistently with the types in dev, qa, beta, staging, production it would then break all the environments and wouldn't be fixed unless fixed in all the environments?
because this is what i changed my code to locally:

  useEffect(() => {
    if (auth.user && auth.user.email && auth.user.name && auth.isAuthenticated && !auth.isLoading) {
      logdna.clearContext();
      const logDnaContext = {
        env: `${CONFIG.env}`,
        app: 'Tradeweb-User-Interface',
        userName: `${auth.user.name}`,
        userEmail: `${auth.user.email}`
      }
      logdna.addContext(logDnaContext);
      console.log('logdna add context', logDnaContext);
    } else {
      logdna.clearContext();
      const logDnaContext = {
        env: `${CONFIG.env}`,
        app: 'Tradeweb-User-Interface',
        userName: `Not User`,
        userEmail: `No User`
      }
      logdna.addContext(logDnaContext);
      console.log('logdna add context', logDnaContext);
    }
  }, [auth.user, auth.isAuthenticated, auth.isAuthenticated])

@BryantDavis1986
Copy link
Author

If you look at the first screen shot, it appears that you are attempting to add the string "(app=Tradeweb-User-Interface, userEmail=cypress-buyer@alphaledger.com, env=ga, userName=Cypres Underwriter) " to the meta.context but meta.context expects an object and there is unable to parse it. The indexer will reset ever 24 hours or so but during that time the data types should not change. So if the first log that come through provides the meta.context as an object then the rest of the lines should be the same or if meta.context first got set as a string the every other time meta.context should be a string until it resets.

i create a new key and app name for me to test this out but i am still running into issues. like this:
image
i guess i am confused on how with a new key and app and the context being set is 100% always the same type which is strings. how the value types can be inconsistent

@BryantDavis1986
Copy link
Author

very first log with a new key, new hostname new app name:
image

@TerryMooreII
Copy link
Collaborator

I believe this index is for the entire account and not based on the specific key, host name or app name. I will double check this and let you know if that is incorrect.

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