Skip to content

Commit 6af6433

Browse files
committed
improve
1 parent dbfe2d3 commit 6af6433

4 files changed

Lines changed: 20 additions & 28 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66

77
- Attach MDC properties to logs as attributes ([#4786](https://github.com/getsentry/sentry-java/pull/4786))
88
- MDC properties set using supported logging frameworks (Logback, Log4j2, java.util.Logging) are now attached to structured logs as attributes
9-
- All properties are sent, and they're subject to server-side data scrubbing. To avoid sending certain properties, use the `beforeSendLog` hook.
109
- This means that you will be able to filter/aggregate logs in the product based on these properties.
10+
- All properties are sent. To avoid sending certain properties, use the `beforeSendLog` hook. You can also set up [Advanced Data
11+
Scrubbing rules](https://docs.sentry.io/security-legal-pii/scrubbing/advanced-datascrubbing/) to redact sensitive information.
1112
- Note that keys containing spaces are not supported.
1213

1314
## 8.23.0

sentry-jul/src/test/kotlin/io/sentry/jul/SentryHandlerTest.kt

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -557,12 +557,11 @@ class SentryHandlerTest {
557557
}
558558

559559
@Test
560-
fun `sets contextTags from MDC as attributes on logs`() {
561-
fixture = Fixture(minimumLevel = Level.INFO, contextTags = listOf("sessionId", "operationId"))
560+
fun `sets properties from MDC as attributes on logs`() {
561+
fixture = Fixture(minimumLevel = Level.INFO, contextTags = listOf("someTag"))
562562

563-
MDC.put("sessionId", "session-123")
564-
MDC.put("operationId", "op-456")
565-
MDC.put("otherTag", "otherValue") // Should not be included in attributes
563+
MDC.put("someTag", "someValue")
564+
MDC.put("otherTag", "otherValue")
566565
fixture.logger.info("testing context tags in logs")
567566

568567
Sentry.flush(1000)
@@ -573,10 +572,8 @@ class SentryHandlerTest {
573572
val log = logs.items.first()
574573
assertEquals("testing context tags in logs", log.body)
575574
val attributes = log.attributes!!
576-
assertEquals("session-123", attributes["sessionId"]?.value)
577-
assertEquals("op-456", attributes["operationId"]?.value)
578-
assertNull(attributes["otherTag"]) // Should not be included as it's not in contextTags
579-
assertEquals("auto.log.jul", attributes["sentry.origin"]?.value)
575+
assertEquals("someValue", attributes["someTag"]?.value)
576+
assertEquals("otherValue", attributes["otherTag"]?.value)
580577
}
581578
)
582579
}

sentry-log4j2/src/test/kotlin/io/sentry/log4j2/SentryAppenderTest.kt

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -593,14 +593,13 @@ class SentryAppenderTest {
593593
}
594594

595595
@Test
596-
fun `sets contextTags from ThreadContext as attributes on logs`() {
596+
fun `sets properties from ThreadContext as attributes on logs`() {
597597
val logger =
598-
fixture.getSut(minimumLevel = Level.INFO, contextTags = listOf("traceId", "spanId"))
598+
fixture.getSut(minimumLevel = Level.INFO, contextTags = listOf("someTag"))
599599
ScopesAdapter.getInstance().options.logs.isEnabled = true
600600

601-
ThreadContext.put("traceId", "trace-123")
602-
ThreadContext.put("spanId", "span-456")
603-
ThreadContext.put("otherTag", "otherValue") // Should not be included in attributes
601+
ThreadContext.put("someTag", "someValue")
602+
ThreadContext.put("otherTag", "otherValue")
604603
logger.info("testing context tags in logs")
605604

606605
Sentry.flush(1000)
@@ -611,10 +610,8 @@ class SentryAppenderTest {
611610
val log = logs.items.first()
612611
assertEquals("testing context tags in logs", log.body)
613612
val attributes = log.attributes!!
614-
assertEquals("trace-123", attributes["traceId"]?.value)
615-
assertEquals("span-456", attributes["spanId"]?.value)
616-
assertNull(attributes["otherTag"]) // Should not be included as it's not in contextTags
617-
assertEquals("auto.log.log4j2", attributes["sentry.origin"]?.value)
613+
assertEquals("someValue", attributes["someTag"]?.value)
614+
assertEquals("otherValue", attributes["otherTag"]?.value)
618615
}
619616
)
620617
}

sentry-logback/src/test/kotlin/io/sentry/logback/SentryAppenderTest.kt

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -823,16 +823,15 @@ class SentryAppenderTest {
823823
}
824824

825825
@Test
826-
fun `sets contextTags from MDC as attributes on logs`() {
826+
fun `sets properties from MDC as attributes on logs`() {
827827
fixture =
828828
Fixture(
829829
minimumLevel = Level.INFO,
830830
enableLogs = true,
831-
contextTags = listOf("requestId", "userId"),
831+
contextTags = listOf("someTag"),
832832
)
833-
MDC.put("requestId", "req-123")
834-
MDC.put("userId", "user-456")
835-
MDC.put("otherTag", "otherValue") // Should not be included in attributes
833+
MDC.put("someTag", "someValue")
834+
MDC.put("otherTag", "otherValue")
836835
fixture.logger.info("testing context tags in logs")
837836

838837
Sentry.flush(1000)
@@ -843,10 +842,8 @@ class SentryAppenderTest {
843842
val log = logs.items.first()
844843
assertEquals("testing context tags in logs", log.body)
845844
val attributes = log.attributes!!
846-
assertEquals("req-123", attributes["requestId"]?.value)
847-
assertEquals("user-456", attributes["userId"]?.value)
848-
assertNull(attributes["otherTag"]) // Should not be included as it's not in contextTags
849-
assertEquals("auto.log.logback", attributes["sentry.origin"]?.value)
845+
assertEquals("someValue", attributes["someTag"]?.value)
846+
assertEquals("otherValue", attributes["otherTag"]?.value)
850847
}
851848
)
852849
}

0 commit comments

Comments
 (0)