Java Code Examples for com.google.cloud.logging.LogEntry#Builder
The following examples show how to use
com.google.cloud.logging.LogEntry#Builder .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TraceIdLoggingEnhancer.java From spring-cloud-gcp with Apache License 2.0 | 6 votes |
/** * Set the trace and span ID fields of the log entry to the current one. * <p>The current trace ID is either the trace ID stored in the Mapped Diagnostic Context (MDC) * under the "X-B3-TraceId" key or, if none set, the current trace ID set by * {@link #setCurrentTraceId(String)}. The current span ID is retrieved from the MDC * under the "X-B3-SpanId" key, if set. * <p>The trace ID is set in the log entry in the "projects/[GCP_PROJECT_ID]/traces/[TRACE_ID]" * format, in order to be associated to traces by the Google Cloud Console. * <p>If an application is running on Google App Engine, the trace ID is also stored in the * "appengine.googleapis.com/trace_id" field, in order to enable log correlation on the logs * viewer. * @param builder log entry builder */ @Override public void enhanceLogEntry(LogEntry.Builder builder) { // In order not to duplicate the whole google-cloud-logging-logback LoggingAppender to add // the trace ID from the MDC there, we're doing it here. // This requires a call to the org.slf4j package. String traceId = org.slf4j.MDC.get(StackdriverTraceConstants.MDC_FIELD_TRACE_ID); String spanId = org.slf4j.MDC.get(StackdriverTraceConstants.MDC_FIELD_SPAN_ID); if (traceId == null) { traceId = getCurrentTraceId(); } if (traceId != null) { builder.setTrace(StackdriverTraceConstants.composeFullTraceName( this.projectIdProvider.getProjectId(), traceId)); if (this.runningOnAppEngine) { builder.addLabel(APP_ENGINE_LABEL_NAME, traceId); } } if (spanId != null) { builder.setSpanId(spanId); } }
Example 2
Source File: OpenCensusTraceLoggingEnhancerTest.java From opencensus-java with Apache License 2.0 | 5 votes |
private static LogEntry getEnhancedLogEntry(LoggingEnhancer loggingEnhancer, Span span) { Scope scope = tracer.withSpan(span); try { LogEntry.Builder builder = LogEntry.newBuilder(null); loggingEnhancer.enhanceLogEntry(builder); return builder.build(); } finally { scope.close(); } }
Example 3
Source File: OpenCensusTraceLoggingEnhancer.java From opencensus-java with Apache License 2.0 | 4 votes |
@Override public void enhanceLogEntry(LogEntry.Builder builder) { addTracingData(tracePrefix, getCurrentSpanContext(), builder); }
Example 4
Source File: OpenCensusTraceLoggingEnhancer.java From opencensus-java with Apache License 2.0 | 4 votes |
private static void addTracingData( String tracePrefix, SpanContext span, LogEntry.Builder builder) { builder.setTrace(formatTraceId(tracePrefix, span.getTraceId())); builder.setSpanId(span.getSpanId().toLowerBase16()); builder.setTraceSampled(span.getTraceOptions().isSampled()); }
Example 5
Source File: ExampleEnhancer.java From java-docs-samples with Apache License 2.0 | 4 votes |
@Override public void enhanceLogEntry(LogEntry.Builder logEntry) { // add additional labels logEntry.addLabel("test-label-1", "test-value-1"); }
Example 6
Source File: ExampleEnhancer.java From java-docs-samples with Apache License 2.0 | 4 votes |
@Override public void enhanceLogEntry(LogEntry.Builder logEntry) { // add additional labels logEntry.addLabel("test-label-1", "test-value-1"); }