Repository navigation
Internal - Split context propagator into TraceState and TraceOptions #644
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
.../shared/src/main/java/com/solarwinds/opentelemetry/extensions/TraceOptionsPropagator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| * © SolarWinds Worldwide, LLC. All rights reserved. | ||
| * | ||
| * 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.solarwinds.opentelemetry.extensions; | ||
|
|
||
| import com.solarwinds.joboe.sampling.XtraceOptions; | ||
| import io.opentelemetry.api.trace.Span; | ||
| import io.opentelemetry.context.Context; | ||
| import io.opentelemetry.context.propagation.TextMapGetter; | ||
| import io.opentelemetry.context.propagation.TextMapPropagator; | ||
| import io.opentelemetry.context.propagation.TextMapSetter; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
|
|
||
| public class TraceOptionsPropagator implements TextMapPropagator { | ||
| static final String X_TRACE_OPTIONS = "X-Trace-Options"; | ||
| static final String X_TRACE_OPTIONS_SIGNATURE = "X-Trace-Options-Signature"; | ||
|
|
||
| @Override | ||
| public Collection<String> fields() { | ||
| return Collections.emptyList(); | ||
| } | ||
|
|
||
| /** | ||
| * Injects the x-trace-options and its signature into the carrier with values provided by current | ||
| * context | ||
| * | ||
| * @param context trace context | ||
| * @param carrier the input to the method being instrumented. Usually a request of some kind | ||
| * @param setter the object that knows how to inject data into carrier using preconfigured keys | ||
| */ | ||
| @Override | ||
| public <C> void inject(Context context, C carrier, TextMapSetter<C> setter) { | ||
| if (carrier == null || !Span.fromContext(context).getSpanContext().isValid()) { | ||
| return; | ||
| } | ||
|
|
||
| final String traceOptions = context.get(TriggerTraceContextKey.XTRACE_OPTIONS); | ||
| final String traceOptionsSignature = | ||
| context.get(TriggerTraceContextKey.XTRACE_OPTIONS_SIGNATURE); | ||
|
|
||
| if (traceOptions != null) { | ||
| setter.set(carrier, X_TRACE_OPTIONS, traceOptions); | ||
| } | ||
|
|
||
| if (traceOptionsSignature != null) { | ||
| setter.set(carrier, X_TRACE_OPTIONS_SIGNATURE, traceOptionsSignature); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Extracts x-trace-options and its signature from carrier and populates the extracted data into | ||
| * the current trace context. | ||
| * | ||
| * @param context trace context | ||
| * @param carrier the input to the method being instrumented. Usually a request of some kind | ||
| * @param getter the object that knows how to extract data from carrier using preconfigured keys | ||
| * @return updated context | ||
| */ | ||
| @Override | ||
| public <C> Context extract(Context context, C carrier, TextMapGetter<C> getter) { | ||
| final String traceOptions = getter.get(carrier, X_TRACE_OPTIONS); | ||
| final String traceOptionsSignature = getter.get(carrier, X_TRACE_OPTIONS_SIGNATURE); | ||
|
|
||
| final XtraceOptions xTraceOptions = | ||
| XtraceOptions.getXtraceOptions(traceOptions, traceOptionsSignature); | ||
|
|
||
| if (xTraceOptions != null) { | ||
| context = context.with(TriggerTraceContextKey.KEY, xTraceOptions); | ||
| context = context.with(TriggerTraceContextKey.XTRACE_OPTIONS, traceOptions); | ||
|
|
||
| if (traceOptionsSignature != null) { | ||
| context = | ||
| context.with(TriggerTraceContextKey.XTRACE_OPTIONS_SIGNATURE, traceOptionsSignature); | ||
| } | ||
| } | ||
|
|
||
| return context; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
.../com/solarwinds/opentelemetry/extensions/config/provider/TraceStateComponentProvider.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| /* | ||
| * © SolarWinds Worldwide, LLC. All rights reserved. | ||
| * | ||
| * 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.solarwinds.opentelemetry.extensions.config.provider; | ||
|
|
||
| import com.google.auto.service.AutoService; | ||
| import com.solarwinds.opentelemetry.extensions.TraceStatePropagator; | ||
| import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; | ||
| import io.opentelemetry.context.propagation.TextMapPropagator; | ||
| import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; | ||
|
|
||
| @AutoService(ComponentProvider.class) | ||
| public class TraceStateComponentProvider implements ComponentProvider { | ||
|
|
||
| public static final String COMPONENT_NAME = "swo_tracestate"; | ||
|
|
||
| @Override | ||
| public Class<TextMapPropagator> getType() { | ||
| return TextMapPropagator.class; | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return COMPONENT_NAME; | ||
| } | ||
|
|
||
| @Override | ||
| public TextMapPropagator create(DeclarativeConfigProperties declarativeConfigProperties) { | ||
| return new TraceStatePropagator(); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.