---
title: "Advanced Usage"
description: "Learn about adding extra data using the MDC system provided by SLF4j."
url: https://docs.sentry.io/platforms/java/guides/jul/usage/advanced-usage/
---

# Advanced Usage | Sentry for java.util.logging

You can add extra data to events using [the MDC system](https://www.slf4j.org/api/org/slf4j/helpers/BasicMDCAdapter.html) for any SLF4J implementation supporting MDC that's on a classpath, (for example Logback, Log4j2, JUL).

```xml
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-jdk14</artifactId>
    <version>1.7.30</version>
</dependency>
```

#### [Mapped Tags](https://docs.sentry.io/platforms/java/guides/jul/usage/advanced-usage.md#mapped-tags)

By default all MDC parameters are stored under the “MDC” tab in Sentry.

```java
import java.util.logging.Level;
import org.slf4j.MDC;

void logWithExtras() {
  // MDC extras
  MDC.put("Environment", "Development");
  MDC.put("OS", "Linux");

  // This sends an event where the Environment and OS MDC values are set as MDC entries
  logger.log(Level.SEVERE, "This is a test");
}
```

Note that MDC manages data on a per-thread basis, and that a child thread does not automatically inherit MDC properties from its parent.

### [In Practice](https://docs.sentry.io/platforms/java/guides/jul/usage/advanced-usage.md#in-practice)

```java
import io.sentry.Sentry;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.slf4j.MDC;

public class MyClass {
  private final Logger logger = Logger.getLogger(MyClass.class.getName());

  void logSimpleMessage() {
    // This sends a simple event to Sentry
    logger.severe("This is a test");
  }

  void logWithBreadcrumbs() {
    // Record a breadcrumb that will be sent with the next event(s),
    // by default the last 100 breadcrumbs are kept.
    Sentry.addBreadcrumb("User made an action");

    // Log entries below `minimumEventLevel` and above or equal to `minimumBreadcrumbLevel`
    // are recorded as breadcrumbs
    logger.info("User made another action");

    // This sends a simple event to Sentry
    logger.severe("This is a test");
  }

  void logWithExtras() {
    // MDC extras
    MDC.put("extra_key", "extra_value");
    // This sends an event with extra data to Sentry
    logger.severe("This is a test");
  }

  void logException() {
    try {
      unsafeMethod();
    } catch (Exception e) {
      // This sends an exception event to Sentry
      logger.log(Level.SEVERE, "Exception caught", e);
    }
  }

  void unsafeMethod() {
    throw new UnsupportedOperationException("You shouldn't call this!");
  }
}
```

## [Context Tags](https://docs.sentry.io/platforms/java/guides/jul/usage/advanced-usage.md#context-tags)

Starting with Sentry version 6.0.0 and up, you can define a list of `MDC tags` that will be viewable as `Tags` in the Sentry UI. `MDC Tags` not in this list will be viewable as `Context Data`.

As of Sentry Java SDK version 8.24.0, `contextTags` also applies to [structured logs](https://docs.sentry.io/product/explore/logs.md). MDC properties matching the configured `contextTags` will be attached to log entries as attributes, prefixed with "mdc.".

To define a tag that shall be sent with events and logs, add a `context-tags` entry with the tags as comma-separated items to the `sentry.properties` file.

```properties
dsn=___PUBLIC_DSN___
context-tags=userId,requestId
```

When you call `MDC.put("userId", "myUserId")` with the above configuration in place, the `userId` will show up as a `tag` on the event in the Sentry UI.
