Skip to content

Commit 238681b

Browse files
committed
cleanup and rename locals to scope
1 parent 2466290 commit 238681b

File tree

2 files changed

+36
-36
lines changed

2 files changed

+36
-36
lines changed

instrumentation/google-http-client-1.19/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/googlehttpclient/GoogleHttpRequestInstrumentation.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,28 @@ public void transform(TypeTransformer transformer) {
5050
this.getClass().getName() + "$ExecuteAsyncAdvice");
5151
}
5252

53-
public static class AdviceLocals {
53+
public static class AdviceScope {
5454

5555
private static final VirtualField<HttpRequest, Context> virtualField =
5656
VirtualField.find(HttpRequest.class, Context.class);
5757
private final Context context;
5858
private final Scope scope;
5959

60-
public AdviceLocals(Context context, Scope scope) {
60+
public AdviceScope(Context context, Scope scope) {
6161
this.context = context;
6262
this.scope = scope;
6363
}
6464

6565
@Nullable
66-
public static AdviceLocals start(HttpRequest request) {
66+
public static AdviceScope start(HttpRequest request) {
6767

6868
Context parentContext = currentContext();
6969
if (!instrumenter().shouldStart(parentContext, request)) {
7070
return null;
7171
}
7272

7373
Context context = instrumenter().start(parentContext, request);
74-
return new AdviceLocals(context, context.makeCurrent());
74+
return new AdviceScope(context, context.makeCurrent());
7575
}
7676

7777
public void end(HttpRequest request, HttpResponse response, Throwable throwable) {
@@ -86,12 +86,12 @@ public void endWhenThrown(HttpRequest request, Throwable throwable) {
8686
}
8787
}
8888

89-
public static AdviceLocals fromVirtualFieldContext(HttpRequest request) {
89+
public static AdviceScope fromVirtualFieldContext(HttpRequest request) {
9090
Context context = virtualField.get(request);
9191
if (context == null) {
9292
return null;
9393
}
94-
return new AdviceLocals(context, context.makeCurrent());
94+
return new AdviceScope(context, context.makeCurrent());
9595
}
9696

9797
public void storeContextToVirtualField(HttpRequest request) {
@@ -104,28 +104,28 @@ public static class ExecuteAdvice {
104104

105105
@Nullable
106106
@Advice.OnMethodEnter(suppress = Throwable.class)
107-
public static AdviceLocals methodEnter(@Advice.This HttpRequest request) {
107+
public static AdviceScope methodEnter(@Advice.This HttpRequest request) {
108108

109-
AdviceLocals locals = AdviceLocals.fromVirtualFieldContext(request);
110-
if (locals != null) {
109+
AdviceScope scope = AdviceScope.fromVirtualFieldContext(request);
110+
if (scope != null) {
111111
// span was created by GoogleHttpClientAsyncAdvice instrumentation below
112112
// (executeAsync ends up calling execute from a separate thread)
113113
// so make it current and end it in method exit
114-
return locals;
114+
return scope;
115115
}
116116

117-
return AdviceLocals.start(request);
117+
return AdviceScope.start(request);
118118
}
119119

120120
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
121121
public static void methodExit(
122122
@Advice.This HttpRequest request,
123123
@Advice.Return HttpResponse response,
124124
@Advice.Thrown Throwable throwable,
125-
@Advice.Enter @Nullable AdviceLocals locals) {
125+
@Advice.Enter @Nullable AdviceScope scope) {
126126

127-
if (locals != null) {
128-
locals.end(request, response, throwable);
127+
if (scope != null) {
128+
scope.end(request, response, throwable);
129129
}
130130
}
131131
}
@@ -135,9 +135,9 @@ public static class ExecuteAsyncAdvice {
135135

136136
@Nullable
137137
@Advice.OnMethodEnter(suppress = Throwable.class)
138-
public static AdviceLocals methodEnter(@Advice.This HttpRequest request) {
138+
public static AdviceScope methodEnter(@Advice.This HttpRequest request) {
139139

140-
AdviceLocals locals = AdviceLocals.start(request);
140+
AdviceScope locals = AdviceScope.start(request);
141141
if (locals != null) {
142142
locals.storeContextToVirtualField(request);
143143
}
@@ -148,10 +148,10 @@ public static AdviceLocals methodEnter(@Advice.This HttpRequest request) {
148148
public static void methodExit(
149149
@Advice.This HttpRequest request,
150150
@Advice.Thrown Throwable throwable,
151-
@Advice.Enter @Nullable AdviceLocals locals) {
151+
@Advice.Enter @Nullable AdviceScope scope) {
152152

153-
if (locals != null) {
154-
locals.endWhenThrown(request, throwable);
153+
if (scope != null) {
154+
scope.endWhenThrown(request, throwable);
155155
}
156156
}
157157
}

instrumentation/java-http-client/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/javahttpclient/HttpClientInstrumentation.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,43 +67,43 @@ public void transform(TypeTransformer transformer) {
6767
HttpClientInstrumentation.class.getName() + "$SendAsyncAdvice");
6868
}
6969

70-
public static class AdviceLocals {
70+
public static class AdviceScope {
7171
private final Context context;
7272
private final Context parentContext;
7373
private final Scope scope;
7474
private final CallDepth callDepth;
7575

76-
private AdviceLocals(Context parentContext, Context context, Scope scope, CallDepth callDepth) {
76+
private AdviceScope(Context parentContext, Context context, Scope scope, CallDepth callDepth) {
7777
this.parentContext = parentContext;
7878
this.context = context;
7979
this.scope = scope;
8080
this.callDepth = callDepth;
8181
}
8282

8383
@Nullable
84-
public static AdviceLocals start(HttpRequest request) {
84+
public static AdviceScope start(HttpRequest request) {
8585
return start(request, null);
8686
}
8787

88-
private static AdviceLocals start(HttpRequest request, CallDepth callDepth) {
88+
private static AdviceScope start(HttpRequest request, CallDepth callDepth) {
8989
Context parentContext = currentContext();
9090
if (!instrumenter().shouldStart(parentContext, request)) {
9191
return null;
9292
}
9393

9494
Context context = instrumenter().start(parentContext, request);
95-
return new AdviceLocals(parentContext, context, context.makeCurrent(), callDepth);
95+
return new AdviceScope(parentContext, context, context.makeCurrent(), callDepth);
9696
}
9797

9898
public void end(HttpRequest request, HttpResponse<?> response, Throwable throwable) {
9999
scope.close();
100100
instrumenter().end(context, request, response, throwable);
101101
}
102102

103-
public static AdviceLocals startWithCallDepth(HttpRequest httpRequest) {
103+
public static AdviceScope startWithCallDepth(HttpRequest httpRequest) {
104104
CallDepth callDepth = CallDepth.forClass(HttpClient.class);
105105
if (callDepth.getAndIncrement() > 0) {
106-
return new AdviceLocals(null, null, null, callDepth);
106+
return new AdviceScope(null, null, null, callDepth);
107107
}
108108
return start(httpRequest, callDepth);
109109
}
@@ -134,19 +134,19 @@ public static class SendAdvice {
134134

135135
@Nullable
136136
@Advice.OnMethodEnter(suppress = Throwable.class)
137-
public static AdviceLocals methodEnter(@Advice.Argument(value = 0) HttpRequest httpRequest) {
138-
return AdviceLocals.start(httpRequest);
137+
public static AdviceScope methodEnter(@Advice.Argument(value = 0) HttpRequest httpRequest) {
138+
return AdviceScope.start(httpRequest);
139139
}
140140

141141
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
142142
public static void methodExit(
143143
@Advice.Argument(0) HttpRequest httpRequest,
144144
@Advice.Return HttpResponse<?> httpResponse,
145145
@Advice.Thrown Throwable throwable,
146-
@Advice.Enter @Nullable AdviceLocals locals) {
146+
@Advice.Enter @Nullable AdviceScope scope) {
147147

148-
if (locals != null) {
149-
locals.end(httpRequest, httpResponse, throwable);
148+
if (scope != null) {
149+
scope.end(httpRequest, httpResponse, throwable);
150150
}
151151
}
152152
}
@@ -155,8 +155,8 @@ public static void methodExit(
155155
public static class SendAsyncAdvice {
156156

157157
@Advice.OnMethodEnter(suppress = Throwable.class)
158-
public static AdviceLocals methodEnter(@Advice.Argument(value = 0) HttpRequest httpRequest) {
159-
return AdviceLocals.startWithCallDepth(httpRequest);
158+
public static AdviceScope methodEnter(@Advice.Argument(value = 0) HttpRequest httpRequest) {
159+
return AdviceScope.startWithCallDepth(httpRequest);
160160
}
161161

162162
@AssignReturned.ToReturned
@@ -165,16 +165,16 @@ public static CompletableFuture<HttpResponse<?>> methodExit(
165165
@Advice.Argument(value = 0) HttpRequest httpRequest,
166166
@Advice.Return CompletableFuture<HttpResponse<?>> originalFuture,
167167
@Advice.Thrown Throwable throwable,
168-
@Advice.Enter AdviceLocals locals) {
168+
@Advice.Enter AdviceScope scope) {
169169

170170
@SuppressWarnings("UnnecessaryLocalVariable")
171171
CompletableFuture<HttpResponse<?>> future = originalFuture;
172172

173-
if (!locals.endWithCallDepth(httpRequest, throwable)) {
173+
if (!scope.endWithCallDepth(httpRequest, throwable)) {
174174
return future;
175175
}
176176

177-
return locals.wrapFuture(future, httpRequest);
177+
return scope.wrapFuture(future, httpRequest);
178178
}
179179
}
180180
}

0 commit comments

Comments
 (0)