-
Notifications
You must be signed in to change notification settings - Fork 849
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
[Do not merge] Initial prototype for context-prop overhaul. #655
Changes from 1 commit
3034102
b50692d
0e34dbf
6fe74d8
145aa9d
03128f3
dc52704
70e0164
d6c9dfa
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright 2019, OpenTelemetry Authors | ||
* | ||
* 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 io.opentelemetry.context; | ||
|
||
public final class Context { | ||
private final io.grpc.Context ctx; | ||
|
||
private Context(io.grpc.Context ctx) { | ||
this.ctx = ctx; | ||
} | ||
|
||
public static Context current() { | ||
return new Context(io.grpc.Context.current()); | ||
} | ||
|
||
public static Scope setCurrent(Context ctx) { | ||
return new ScopeImpl(ctx); | ||
} | ||
|
||
public static <T> Context.Key<T> createKey(String name) { | ||
return new Key<T>(io.grpc.Context.<T>key(name)); | ||
} | ||
|
||
public <T> T getValue(Context.Key<T> key) { | ||
return key.key().get(ctx); | ||
} | ||
|
||
public <T> Context setValue(Context.Key<T> key, T value) { | ||
return new Context(ctx.withValue(key.key(), value)); | ||
} | ||
|
||
public static final class Key<T> { | ||
io.grpc.Context.Key<T> key; | ||
|
||
private Key(io.grpc.Context.Key<T> key) { | ||
this.key = key; | ||
} | ||
|
||
io.grpc.Context.Key<T> key() { | ||
return key; | ||
} | ||
} | ||
|
||
static final class ScopeImpl implements Scope { | ||
private final io.grpc.Context ctx; | ||
private final io.grpc.Context prevCtx; | ||
|
||
public ScopeImpl(Context ctx) { | ||
this.ctx = ctx.ctx; | ||
this.prevCtx = ctx.ctx.attach(); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
ctx.detach(prevCtx); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2019, OpenTelemetry Authors | ||
* | ||
* 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 io.opentelemetry.context.propagation; | ||
|
||
import io.opentelemetry.context.Context; | ||
import javax.annotation.Nullable; | ||
|
||
public interface HttpExtractor { | ||
<C> Context extract(Context ctx, Getter<C> getter); | ||
|
||
interface Getter<C> { | ||
@Nullable | ||
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. As discussed in our meeting today, This interface should have another method that provides access to all the headers: Iterable<String> headers(); |
||
String get(C carrier, String key); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2019, OpenTelemetry Authors | ||
* | ||
* 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 io.opentelemetry.context.propagation; | ||
|
||
import io.opentelemetry.context.Context; | ||
|
||
public interface HttpInjector { | ||
<C> void inject(Context ctx, C carrier, Setter<C> setter); | ||
|
||
interface Setter<C> { | ||
void put(C carrier, String key, String value); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2019, OpenTelemetry Authors | ||
* | ||
* 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 io.opentelemetry.distributedcontext; | ||
|
||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.context.propagation.HttpExtractor; | ||
import io.opentelemetry.context.propagation.HttpInjector; | ||
|
||
public interface BaggageManager { | ||
public Context setValue(Context ctx, String key, String value); | ||
|
||
public String getValue(Context ctx, String key); | ||
|
||
public void removeValue(Context ctx, String key); | ||
|
||
public void clear(Context ctx); | ||
|
||
public HttpInjector getHttpInjector(); | ||
|
||
public HttpExtractor getHttpExtractor(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2019, OpenTelemetry Authors | ||
* | ||
* 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 io.opentelemetry.distributedcontext; | ||
|
||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.context.propagation.HttpExtractor; | ||
import io.opentelemetry.context.propagation.HttpInjector; | ||
import java.util.List; | ||
|
||
public interface CorrelationsManager { | ||
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. Is this what we called Tags in opencensus? I like Tags better. 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. Yes - I called this 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. Please tell @tedsuo that Tags is a better name :) 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. @bogdandrutu you and @yurishkuro have a jello wrestling match, the winner can pick the name. :) |
||
public Context setValue(Context ctx, CorrelationLabel label, HopLimit hopLimit); | ||
|
||
public Context setValues(Context ctx, List<CorrelationLabel> labels, HopLimit hopLimit); | ||
|
||
public interface CorrelationLabel { | ||
public String key(); | ||
|
||
public String value(); | ||
} | ||
|
||
public enum HopLimit { | ||
NO_PROPAGATION, | ||
UNLIMITED_PROPAGATION | ||
} | ||
|
||
public HttpInjector getHttpInjector(); | ||
|
||
public HttpExtractor getHttpExtractor(); | ||
} |
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.
If we add this class we also need all the helpers:
Also we need to make sure somehow that users are not double wrapping things with this Context and io.grpc.Context when they use both opentelemetry and io.grpc.Context.
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.
Good point, yes. Although I wonder if we could postpone them (for a second version), or you think we would need them right from the start?
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.
Without them users cannot instrument their code. That is the main reason I actually used directly the grpc one, to not duplicate code unnecessary.
I would like to see how an RPC integration will look like with the new Injector/Extractor