Skip to content

Commit

Permalink
Add trace.id to indexed deprecation logs (#81524)
Browse files Browse the repository at this point in the history
#75331 missed adding
trace.id to indexed deprecation logs (these use ECSJsonLayout instead of
ESJsonLayout).
  • Loading branch information
pgomulka committed Dec 9, 2021
1 parent 48cbeda commit 6bef861
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void testLayout() {
+ "\"node.name\": \"%node_name\", "
+ "\"message\": \"%notEmpty{%enc{%marker}{JSON} }%enc{%.-10000m}{JSON}\""
+ "%notEmpty{, %node_and_cluster_id }"
+ "%notEmpty{, %trace_id }"
+ "%notEmpty{, \"trace.id\": \"%trace_id\" }"
+ "%exceptionAsJson }"
+ System.lineSeparator()
)
Expand All @@ -63,7 +63,7 @@ public void testLayoutWithAdditionalFields() {
+ "%notEmpty{, \"x-opaque-id\": \"%ESMessageField{x-opaque-id}\"}"
+ "%notEmpty{, \"someOtherField\": \"%ESMessageField{someOtherField}\"}"
+ "%notEmpty{, %node_and_cluster_id }"
+ "%notEmpty{, %trace_id }"
+ "%notEmpty{, \"trace.id\": \"%trace_id\" }"
+ "%exceptionAsJson }"
+ System.lineSeparator()
)
Expand All @@ -86,7 +86,7 @@ public void testLayoutWithAdditionalFieldOverride() {
+ "\"node.name\": \"%node_name\""
+ "%notEmpty{, \"message\": \"%ESMessageField{message}\"}"
+ "%notEmpty{, %node_and_cluster_id }"
+ "%notEmpty{, %trace_id }"
+ "%notEmpty{, \"trace.id\": \"%trace_id\" }"
+ "%exceptionAsJson }"
+ System.lineSeparator()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private String createPattern(Map<String, Object> map, Set<String> esMessageField
separator = ", ";
}
sb.append(notEmpty(", %node_and_cluster_id "));
sb.append(notEmpty(", %trace_id "));
sb.append(notEmpty(", \"trace.id\": \"%trace_id\" "));
sb.append("%exceptionAsJson ");
sb.append("}");
sb.append(System.lineSeparator());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static String getTraceId() {
public void format(LogEvent event, StringBuilder toAppendTo) {
String traceId = getTraceId();
if (traceId != null) {
toAppendTo.append("\"trace.id\": \"" + traceId + "\"");
toAppendTo.append(traceId);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.elasticsearch.common.logging.LoggerMessageFormat;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xcontent.json.JsonXContent;
Expand Down Expand Up @@ -386,7 +387,11 @@ public void testDisableDeprecationLogIndexing() throws Exception {
// triggers two deprecations - endpoint and setting
private Request deprecatedRequest(String method, String xOpaqueId) throws IOException {
final Request getRequest = new Request(method, "/_test_cluster/deprecated_settings");
final RequestOptions options = getRequest.getOptions().toBuilder().addHeader("X-Opaque-Id", xOpaqueId).build();
final RequestOptions options = getRequest.getOptions()
.toBuilder()
.addHeader("X-Opaque-Id", xOpaqueId)
.addHeader("traceparent", "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01")
.build();
getRequest.setOptions(options);
getRequest.setEntity(
buildSettingsRequest(
Expand Down Expand Up @@ -419,6 +424,7 @@ public void testDeprecationMessagesCanBeIndexed() throws Exception {
hasKey("elasticsearch.cluster.name"),
hasKey("elasticsearch.cluster.uuid"),
hasEntry(X_OPAQUE_ID_FIELD_NAME, "xOpaqueId-testDeprecationMessagesCanBeIndexed"),
hasEntry(Task.TRACE_ID, "0af7651916cd43dd8448eb211c80319c"),
hasEntry("elasticsearch.event.category", "settings"),
hasKey("elasticsearch.node.id"),
hasKey("elasticsearch.node.name"),
Expand All @@ -437,6 +443,7 @@ public void testDeprecationMessagesCanBeIndexed() throws Exception {
hasKey("elasticsearch.cluster.name"),
hasKey("elasticsearch.cluster.uuid"),
hasEntry(X_OPAQUE_ID_FIELD_NAME, "xOpaqueId-testDeprecationMessagesCanBeIndexed"),
hasEntry(Task.TRACE_ID, "0af7651916cd43dd8448eb211c80319c"),
hasEntry("elasticsearch.event.category", "api"),
hasKey("elasticsearch.node.id"),
hasKey("elasticsearch.node.name"),
Expand Down Expand Up @@ -465,6 +472,7 @@ public void testDeprecationWarnMessagesCanBeIndexed() throws Exception {
final RequestOptions options = request.getOptions()
.toBuilder()
.addHeader("X-Opaque-Id", "xOpaqueId-testDeprecationWarnMessagesCanBeIndexed")
.addHeader("traceparent", "00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-01")
.build();
request.setOptions(options);
request.setEntity(
Expand All @@ -489,6 +497,7 @@ public void testDeprecationWarnMessagesCanBeIndexed() throws Exception {
hasKey("elasticsearch.cluster.name"),
hasKey("elasticsearch.cluster.uuid"),
hasEntry(X_OPAQUE_ID_FIELD_NAME, "xOpaqueId-testDeprecationWarnMessagesCanBeIndexed"),
hasEntry(Task.TRACE_ID, "0af7651916cd43dd8448eb211c80319c"),
hasEntry("elasticsearch.event.category", "settings"),
hasKey("elasticsearch.node.id"),
hasKey("elasticsearch.node.name"),
Expand All @@ -507,6 +516,7 @@ public void testDeprecationWarnMessagesCanBeIndexed() throws Exception {
hasKey("elasticsearch.cluster.name"),
hasKey("elasticsearch.cluster.uuid"),
hasEntry(X_OPAQUE_ID_FIELD_NAME, "xOpaqueId-testDeprecationWarnMessagesCanBeIndexed"),
hasEntry(Task.TRACE_ID, "0af7651916cd43dd8448eb211c80319c"),
hasEntry("elasticsearch.event.category", "api"),
hasKey("elasticsearch.node.id"),
hasKey("elasticsearch.node.name"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ protected String pattern(String dataset, String[] esMessageFields) {
map.put("elasticsearch.cluster.uuid", inQuotes("%cluster_id"));
map.put("elasticsearch.node.id", inQuotes("%node_id"));
map.put("elasticsearch.node.name", inQuotes("%node_name"));
map.put("trace.id", inQuotes("%notEmpty{%trace_id}"));
map.put("message", inQuotes("%notEmpty{%enc{%marker}{JSON} }%enc{%.-10000m}{JSON}"));
map.put("data_stream.type", inQuotes("logs"));
map.put("data_stream.dataset", inQuotes("deprecation.elasticsearch"));
Expand Down

0 comments on commit 6bef861

Please sign in to comment.