Skip to content

Sampling overrides do not work for stacktrace attribute (at least in log4j2) #1973

Closed
@morngaraf

Description

@morngaraf

Expected behavior

Sampling overrides should work for stacktrace attribute applicationinsights.internal.log_error_stack.

Actual behavior

It does not work, pattern matcher is never executed with the provided regexp.

To Reproduce

Steps to reproduce the behavior:

  1. Set the following sampling overrides in applicationinsights.json:
  "sampling": {
    "percentage": 100
  },
  "preview": {
    "sampling": {
      "overrides": [
        {
          "attributes": [
            {
              "key": "applicationinsights.internal.log_error_stack",
              "value": "<some valid regexp>",
              "matchType": "regexp"
            }
          ],
          "percentage": 0
        },
        {
          "attributes": [
            {
              "key": "applicationinsights.internal.logger_name",
              "value": "<some other valid regexp, which never matches a value in this attribute>",
              "matchType": "regexp"
            }
          ],
          "percentage": 0
        }
      ]
    }
  }
  1. Let the app log some exception, e.g. logger.error("this is an error with some stacktrace", new IllegalArgumentException("exception message"));
  2. Check logs / fiddler / appinsights, exception has been sent, though sampling is 0. The other option is to set a breakpoint in Pattern.matcher() with condition on pattern: it is hit for logger_name, but not for log_error_stack.

System information

  • SDK Version: agent 3.2.3, Java 17
  • OS type and version: Windows 10 x64, 21H1, 19043.1348
  • Using spring-boot? - yes, 2.5.6
  • Additional relevant libraries (with version, if applicable): configured spring-boot to use log4j2 instead of default logback (probably irrelevant, though I didn't try with default)

Logs

2021-11-24 01:01:34.630+03:00 DEBUG c.m.a.a.internal.exporter.Exporter - exporting span: SpanDataImpl{}, name=this is an error with some stacktrace, kind=INTERNAL, startEpochNanos=1637704894632635000, attributes={applicationinsights.internal.log=true, applicationinsights.internal.log_error_stack="java.lang.IllegalArgumentException: exception message
at ...
at java.base/java.lang.Thread.run(Thread.java:833)
", applicationinsights.internal.log_level="ERROR", applicationinsights.internal.logger_name="MyLoggerName", applicationinsights.internal.operation_name="GET /sample-check", thread.id=68}, events=[], links=[], status=ImmutableStatusData{statusCode=UNSET, description=}, endEpochNanos=1637704894632837500, hasEnded=true, totalRecordedEvents=0, totalRecordedLinks=0, totalAttributeCount=8}

Notes

I'm guessing that stacktrace attribute might be added later than sampling check, because it (attribute) does not seem to exist in the debugger:
image

but it is there in the logs. Not sure if this should be in feature request category.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions