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

Add labels on a per-log basis to Stackdriver upload via Log4net #5325

Closed
williecohen-google opened this issue Sep 15, 2020 · 9 comments
Closed
Assignees
Labels
api: logging Issues related to the Cloud Logging API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@williecohen-google
Copy link

williecohen-google commented Sep 15, 2020

Is your feature request related to a problem? Please describe.
I am using Log4net with the GoogleStackdriverAppender in a .NET framework project. I want to be able to add labels to our log entries for Cloud Monitoring. I want to be able to group logs easily using these labels (which is what their purpose seems to be). However, the GoogleStackdriverAppender only allows static custom labels to be added that apply to all logs flowing through the Appender.

Describe the solution you'd like
Ideally there would be a way to attach labels to certain logs, and not just statically for all logs generated. I'm assuming this decision was made to try and "fit" Log4net nicely into the Stackdriver data model, but I would think there would be a way to accommodate per log labels.

Describe alternatives you've considered

  • Creating multiple appenders. (Seems like a terrible idea?)
  • Creating structured logs to create our own labels at the proto payload level. (Seems like a band aid fix)
@EatonZ EatonZ mentioned this issue Sep 16, 2020
@amanda-tarafa amanda-tarafa added api: logging Issues related to the Cloud Logging API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels Sep 16, 2020
@amanda-tarafa amanda-tarafa self-assigned this Sep 16, 2020
@amanda-tarafa
Copy link
Contributor

I'll take a look at whether we can do this and how, but just to set expectations, I won't get to it for at least a couple of weeks.

@williecohen-google
Copy link
Author

Any updates? We are running into log query latency issues and using log labels would speed things up dramatically (because they are indexed).

@jskeet
Copy link
Collaborator

jskeet commented Nov 6, 2020

@williecohen-google: Sorry, not yet - we'll try to have a look next week.

@amanda-tarafa
Copy link
Contributor

I'm working on this, will have an update early next week.

@amanda-tarafa
Copy link
Contributor

amanda-tarafa commented Nov 13, 2020

I believe you can already achieve this using properties, custom labels and patterns for custom labels.

  • Configure the GoogleStackdriverAppender to use patterns for custom labels by setting the UsePatternWithinCustomLabels property to true.
  • Add costume labels that use patterns to reference properties, like such:
    { "userName", "%property{userName}" }
  • Use any of the log4net GlobaContext, ThreadContext and LogicalThreadContext to set properties.

The only caveat is that if a property is not set, the pattern will return "(null)", so the label will always be set but with a "(null)" value in some instances. Either you filter out the ones with "(null)" values, or we could consider adding a StripNullValuedLabels property to the appender so that we can remove such labels if they existed.

Let me know if this sounds reasonable to you.

@williecohen-google
Copy link
Author

Ok, I think this sounds reasonable. We have a default label, which we could set at GlobalContext to prevent null values, but it would probably be nice for other use cases to strip nulls out. I'll try this out and see if I run into any issues. Thanks!

@williecohen-google
Copy link
Author

Ok I was able to successfully add log labels with this! I do think for a follow up:

  1. This should be documented somewhere (which maybe I missed).
  2. Adding a StripNullValuedLabels property would be useful for adding labels to select logs.

Thanks for looking into this!

@amanda-tarafa
Copy link
Contributor

Thanks for confirming that this solves your issue.

  1. I'll make sure to add some docs/samples around this.
  2. We'll look int it.

I'll keep open until I've added the docs at least.

amanda-tarafa added a commit to amanda-tarafa/google-cloud-dotnet that referenced this issue Nov 18, 2020
amanda-tarafa added a commit to amanda-tarafa/google-cloud-dotnet that referenced this issue Nov 19, 2020
amanda-tarafa added a commit that referenced this issue Nov 19, 2020
amanda-tarafa added a commit to amanda-tarafa/google-cloud-dotnet that referenced this issue Nov 19, 2020
amanda-tarafa added a commit to amanda-tarafa/google-cloud-dotnet that referenced this issue Nov 19, 2020
amanda-tarafa added a commit that referenced this issue Nov 19, 2020
@amanda-tarafa
Copy link
Contributor

I've added documentation on how to translate Log4Net properties into labels. You can find it here.

As for the StripNullValuedLabels property, I've moved this issue to our backlog in #5628 to wait for more user demand.

I'll be closing this issue now since we've done as much as we are planning to do for now, but do please add another comment if you think there's something else we can do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: logging Issues related to the Cloud Logging API. priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

3 participants