newrelic / java-log-extensions

Source for the New Relic Java log framework extensions.
Apache License 2.0
15 stars 22 forks source link

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

Open jasonjkeller opened 11 months ago

jasonjkeller commented 11 months ago

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");
workato-integration[bot] commented 11 months ago

https://new-relic.atlassian.net/browse/NR-171023