-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
integrate and implement open telemetry tracing #18534
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
import com.facebook.presto.spi.security.SelectedRole; | ||
import com.facebook.presto.spi.session.ResourceEstimates; | ||
import com.facebook.presto.spi.tracing.Tracer; | ||
import com.facebook.presto.spi.tracing.TracerHandle; | ||
import com.facebook.presto.spi.tracing.TracerProvider; | ||
import com.facebook.presto.sql.parser.ParsingException; | ||
import com.facebook.presto.sql.parser.ParsingOptions; | ||
|
@@ -211,19 +212,39 @@ else if (nameParts.size() == 2) { | |
|
||
this.sessionFunctions = parseSessionFunctionHeader(servletRequest); | ||
this.sessionPropertyManager = requireNonNull(sessionPropertyManager, "sessionPropertyManager is null"); | ||
String tunnelTraceId = trimEmptyToNull(servletRequest.getHeader(PRESTO_TRACE_TOKEN)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know it's a bit anti pattern; but in order to keep the logic so we don't pollute the |
||
|
||
Map<String, String> requestHeaders = getRequestHeaders(servletRequest); | ||
TracerHandle tracerHandle = tracerProvider.getHandleGenerator().apply(requestHeaders); | ||
|
||
if (isTracingEnabled()) { | ||
this.tracer = Optional.of(requireNonNull(tracerProvider.getNewTracer(), "tracer is null")); | ||
this.tracer = Optional.of(requireNonNull(tracerProvider.getNewTracer(tracerHandle), "tracer is null")); | ||
traceToken = Optional.ofNullable(this.tracer.get().getTracerId()); | ||
} | ||
else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a new branch here: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated trace token to replicate similar logic as before |
||
this.tracer = Optional.of(NoopTracerProvider.NOOP_TRACER); | ||
|
||
// If tunnel trace token is null, we expose the Presto tracing id. | ||
// Otherwise we preserve the ability of trace token tunneling but | ||
// still trace Presto internally for aggregation purposes. | ||
traceToken = Optional.ofNullable(tunnelTraceId == null ? this.tracer.get().getTracerId() : tunnelTraceId); | ||
String tunnelTraceId = trimEmptyToNull(servletRequest.getHeader(PRESTO_TRACE_TOKEN)); | ||
if (tunnelTraceId != null) { | ||
traceToken = Optional.of(tunnelTraceId); | ||
} | ||
else { | ||
traceToken = Optional.ofNullable(tracerHandle.getTraceToken()); | ||
} | ||
} | ||
else { | ||
this.tracer = Optional.of(NoopTracerProvider.NOOP_TRACER); | ||
traceToken = Optional.ofNullable(tunnelTraceId); | ||
} | ||
|
||
private static Map<String, String> getRequestHeaders(HttpServletRequest servletRequest) | ||
{ | ||
ImmutableMap.Builder<String, String> headers = ImmutableMap.builder(); | ||
Enumeration<String> headerNames = servletRequest.getHeaderNames(); | ||
while (headerNames.hasMoreElements()) { | ||
String header = headerNames.nextElement(); | ||
headers.put(header, servletRequest.getHeader(header)); | ||
} | ||
return headers.build(); | ||
} | ||
|
||
public static List<String> splitSessionHeader(Enumeration<String> headers) | ||
|
@@ -502,7 +523,7 @@ public Optional<Tracer> getTracer() | |
*/ | ||
private boolean isTracingEnabled() | ||
{ | ||
String clientValue = systemProperties.getOrDefault(DISTRIBUTED_TRACING_MODE, TracingConfig.DistributedTracingMode.NO_TRACE.name()); | ||
String clientValue = systemProperties.getOrDefault(DISTRIBUTED_TRACING_MODE, ""); | ||
Comment on lines
-505
to
+526
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the property isn't set by the user, it will allow the system default to be used instead of defaulting to no trace. It should be a nice feature to have so applications do not need to change their presto client request to enable tracing, but only need to change their presto application properties. |
||
|
||
// Client session setting overrides everything. | ||
if (clientValue.equalsIgnoreCase(TracingConfig.DistributedTracingMode.ALWAYS_TRACE.name())) { | ||
|
@@ -511,13 +532,13 @@ private boolean isTracingEnabled() | |
if (clientValue.equalsIgnoreCase(TracingConfig.DistributedTracingMode.NO_TRACE.name())) { | ||
return false; | ||
} | ||
if (clientValue.equalsIgnoreCase(TracingConfig.DistributedTracingMode.SAMPLE_BASED.name())) { | ||
return true; | ||
} | ||
|
||
// Client not set, we then take system default value, and only init | ||
// tracing if it's SAMPLE_BASED (TracingConfig prohibits you to | ||
// configure system default to be ALWAYS_TRACE). If property manager | ||
// not provided then false. | ||
// Client not set, we then take system default value if ALWAYS_TRACE (SAMPLE_BASED disabled). If property manager not provided then false. | ||
return sessionPropertyManager | ||
.map(manager -> manager.decodeSystemPropertyValue(DISTRIBUTED_TRACING_MODE, null, TracingConfig.DistributedTracingMode.class) == TracingConfig.DistributedTracingMode.SAMPLE_BASED) | ||
.map(manager -> manager.decodeSystemPropertyValue(DISTRIBUTED_TRACING_MODE, null, String.class).equalsIgnoreCase(TracingConfig.DistributedTracingMode.ALWAYS_TRACE.name())) | ||
.orElse(false); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.facebook.presto.tracing; | ||
|
||
import com.facebook.presto.spi.tracing.TracerHandle; | ||
|
||
public class NoopTracerHandle | ||
implements TracerHandle | ||
{ | ||
private final String traceToken; | ||
|
||
public NoopTracerHandle() | ||
{ | ||
this.traceToken = "noop_dummy_id"; | ||
} | ||
|
||
@Override | ||
public String getTraceToken() | ||
{ | ||
return traceToken; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intended? Or we have a stable release?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, no stable release exists. Versions of each package to use are stated here https://github.com/open-telemetry/opentelemetry-java