Skip to content

Test workaround for adding linking metadata to custom Json layouts and consider documenting it #83

@jasonjkeller

Description

@jasonjkeller

With the java-log-extensions library the intent is for customers to use the NewRelicLayout that formats the logs with New Relic metadata.

For customers that are using a custom Json layout they may be able to get access to the NR metadata that the library makes available so that they can add it to their custom layout by modifying it to directly add the attributes.

Below is an example that was said to work with Log4j2. We should investigate if this is a general approach that could work with any of the supported log libraries or if it would be limited to specific ones, and consider documenting it appropriately where it makes the most sense (in the main project readme if it applies to all supported logging libraries or in the readme for the specific logging libraries that it would work with).

@JsonProperty("entity.guid")
public String getEntityGuid() {
    Map<String, String> contextData = delegate.getContextData().toMap();
    return contextData.get("NewRelic:entity.guid");
}
@JsonProperty("entity.name")
public String getEntityName() {
    Map<String, String> contextData = delegate.getContextData().toMap();
    return contextData.get("NewRelic:entity.name");
}
@JsonProperty("entity.type")
public String getEntityType() {
    Map<String, String> contextData = delegate.getContextData().toMap();
    return contextData.get("NewRelic:entity.type");
}
@JsonProperty("hostname")
public String getHostname() {
    Map<String, String> contextData = delegate.getContextData().toMap();
    return contextData.get("NewRelic:hostname");
}
@JsonProperty("span.id")
public String getSpanId() {
    Map<String, String> contextData = delegate.getContextData().toMap();
    return contextData.get("NewRelic:span.id");
}
@JsonProperty("trace.id")
public String getTraceId() {
    Map<String, String> contextData = delegate.getContextData().toMap();
    return contextData.get("NewRelic:trace.id");

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions