Skip to content

Commit e9962f7

Browse files
committed
Rework of OpenTracingOptions and PR comments addressed.
1 parent 7b2ecd5 commit e9962f7

12 files changed

+226
-201
lines changed

temporal-opentracing/src/main/java/io/temporal/opentracing/OpenTracingClientInterceptor.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,19 @@
2424
import io.temporal.opentracing.internal.OpenTracingWorkflowClientCallsInterceptor;
2525

2626
public class OpenTracingClientInterceptor extends WorkflowClientInterceptorBase {
27+
private final OpenTracingOptions openTracingOptions;
28+
29+
public OpenTracingClientInterceptor() {
30+
this(OpenTracingOptions.newBuilder().build());
31+
}
32+
33+
public OpenTracingClientInterceptor(OpenTracingOptions openTracingOptions) {
34+
this.openTracingOptions = openTracingOptions;
35+
}
2736

2837
@Override
2938
public WorkflowClientCallsInterceptor workflowClientCallsInterceptor(
3039
WorkflowClientCallsInterceptor next) {
31-
return new OpenTracingWorkflowClientCallsInterceptor(next);
40+
return new OpenTracingWorkflowClientCallsInterceptor(next, openTracingOptions);
3241
}
3342
}

temporal-opentracing/src/main/java/io/temporal/opentracing/OpenTracingConfig.java

-125
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (C) 2020 Temporal Technologies, Inc. All Rights Reserved.
3+
*
4+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5+
*
6+
* Modifications copyright (C) 2017 Uber Technologies, Inc.
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
9+
* use this file except in compliance with the License. A copy of the License is
10+
* located at
11+
*
12+
* http://aws.amazon.com/apache2.0
13+
*
14+
* or in the "license" file accompanying this file. This file is distributed on
15+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
16+
* express or implied. See the License for the specific language governing
17+
* permissions and limitations under the License.
18+
*/
19+
20+
package io.temporal.opentracing;
21+
22+
import javax.annotation.Nonnull;
23+
import java.util.HashMap;
24+
import java.util.Map;
25+
26+
public class OpenTracingOptions {
27+
private final Map<SpanOperationType, String> customSpanOperationNamePrefixes;
28+
29+
private OpenTracingOptions(Map<SpanOperationType, String> customSpanOperationNamePrefixes) {
30+
this.customSpanOperationNamePrefixes = customSpanOperationNamePrefixes;
31+
}
32+
33+
@Nonnull
34+
public String getSpanOperationNamePrefix(SpanOperationType spanOperationType) {
35+
return customSpanOperationNamePrefixes.getOrDefault(
36+
spanOperationType, spanOperationType.getDefaultPrefix());
37+
}
38+
39+
public static Builder newBuilder() {
40+
return new Builder();
41+
}
42+
43+
public static final class Builder {
44+
private final Map<SpanOperationType, String> customSpanOperationNamePrefixes = new HashMap<>();
45+
46+
private Builder() {}
47+
48+
public Builder setSpanOperationNamePrefix(
49+
SpanOperationType spanOperationType, String customPrefix) {
50+
this.customSpanOperationNamePrefixes.put(spanOperationType, customPrefix);
51+
return this;
52+
}
53+
54+
public OpenTracingOptions build() {
55+
return new OpenTracingOptions(customSpanOperationNamePrefixes);
56+
}
57+
}
58+
}

temporal-opentracing/src/main/java/io/temporal/opentracing/OpenTracingWorkerInterceptor.java

+12-2
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,23 @@
2424
import io.temporal.opentracing.internal.OpenTracingWorkflowInboundCallsInterceptor;
2525

2626
public class OpenTracingWorkerInterceptor implements WorkerInterceptor {
27+
private final OpenTracingOptions openTracingOptions;
28+
29+
public OpenTracingWorkerInterceptor() {
30+
this(OpenTracingOptions.newBuilder().build());
31+
}
32+
33+
public OpenTracingWorkerInterceptor(OpenTracingOptions openTracingOptions) {
34+
this.openTracingOptions = openTracingOptions;
35+
}
36+
2737
@Override
2838
public WorkflowInboundCallsInterceptor interceptWorkflow(WorkflowInboundCallsInterceptor next) {
29-
return new OpenTracingWorkflowInboundCallsInterceptor(next);
39+
return new OpenTracingWorkflowInboundCallsInterceptor(next, openTracingOptions);
3040
}
3141

3242
@Override
3343
public ActivityInboundCallsInterceptor interceptActivity(ActivityInboundCallsInterceptor next) {
34-
return new OpenTracingActivityInboundCallsInterceptor(next);
44+
return new OpenTracingActivityInboundCallsInterceptor(next, openTracingOptions);
3545
}
3646
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (C) 2020 Temporal Technologies, Inc. All Rights Reserved.
3+
*
4+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5+
*
6+
* Modifications copyright (C) 2017 Uber Technologies, Inc.
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
9+
* use this file except in compliance with the License. A copy of the License is
10+
* located at
11+
*
12+
* http://aws.amazon.com/apache2.0
13+
*
14+
* or in the "license" file accompanying this file. This file is distributed on
15+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
16+
* express or implied. See the License for the specific language governing
17+
* permissions and limitations under the License.
18+
*/
19+
20+
package io.temporal.opentracing;
21+
22+
public enum SpanOperationType {
23+
WORKFLOW_START("StartWorkflow"),
24+
WORKFLOW_START_WITH_SIGNAL("SignalWithStartWorkflow"),
25+
WORKFLOW_RUN("RunWorkflow"),
26+
CHILD_WORKFLOW_START("StartChildWorkflow"),
27+
ACTIVITY_START("StartActivity"),
28+
ACTIVITY_RUN("RunActivity");
29+
30+
private String defaultPrefix;
31+
32+
SpanOperationType(String defaultPrefix) {
33+
this.defaultPrefix = defaultPrefix;
34+
}
35+
36+
public String getDefaultPrefix() {
37+
return defaultPrefix;
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (C) 2020 Temporal Technologies, Inc. All Rights Reserved.
3+
*
4+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
5+
*
6+
* Modifications copyright (C) 2017 Uber Technologies, Inc.
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
9+
* use this file except in compliance with the License. A copy of the License is
10+
* located at
11+
*
12+
* http://aws.amazon.com/apache2.0
13+
*
14+
* or in the "license" file accompanying this file. This file is distributed on
15+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
16+
* express or implied. See the License for the specific language governing
17+
* permissions and limitations under the License.
18+
*/
19+
20+
package io.temporal.opentracing;
21+
22+
public class StandardTags {
23+
public static final String WORKFLOW_ID = "workflowId";
24+
public static final String RUN_ID = "runId";
25+
public static final String PARENT_WORKFLOW_ID = "parentWorkflowId";
26+
public static final String PARENT_RUN_ID = "parentRunId";
27+
}

temporal-opentracing/src/main/java/io/temporal/opentracing/internal/OpenTracingActivityInboundCallsInterceptor.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,19 @@
2828
import io.temporal.activity.ActivityInfo;
2929
import io.temporal.common.interceptors.ActivityInboundCallsInterceptor;
3030
import io.temporal.common.interceptors.ActivityInboundCallsInterceptorBase;
31-
import io.temporal.opentracing.OpenTracingConfig;
31+
import io.temporal.opentracing.OpenTracingOptions;
32+
import io.temporal.opentracing.SpanOperationType;
3233

3334
public class OpenTracingActivityInboundCallsInterceptor
3435
extends ActivityInboundCallsInterceptorBase {
35-
public OpenTracingActivityInboundCallsInterceptor(ActivityInboundCallsInterceptor next) {
36+
private final OpenTracingOptions openTracingOptions;
37+
38+
public OpenTracingActivityInboundCallsInterceptor(
39+
ActivityInboundCallsInterceptor next, OpenTracingOptions openTracingOptions) {
3640
super(next);
41+
this.openTracingOptions = openTracingOptions;
3742
}
3843

39-
private final OpenTracingConfig openTracingConfig = OpenTracingConfig.newBuilder().build();
40-
4144
private ActivityExecutionContext activityExecutionContext;
4245

4346
@Override
@@ -53,13 +56,13 @@ public void init(ActivityExecutionContext context) {
5356
public ActivityOutput execute(ActivityInput input) {
5457
Tracer tracer = GlobalTracer.get();
5558
SpanContext rootSpanContext =
56-
OpenTracingContextPropagationUtils.readSpanContextFromHeader(input.getHeader(), tracer);
59+
OpenTracingContextAccessor.readSpanContextFromHeader(input.getHeader(), tracer);
5760
ActivityInfo activityInfo = activityExecutionContext.getInfo();
5861
Span activityRunSpan =
5962
OpenTracingSpanUtils.createActivityRunSpan(
6063
tracer,
6164
System.currentTimeMillis(),
62-
openTracingConfig.getActivityRunOperationNamePrefix()
65+
openTracingOptions.getSpanOperationNamePrefix(SpanOperationType.ACTIVITY_RUN)
6366
+ "-"
6467
+ activityInfo.getActivityType(),
6568
activityInfo.getWorkflowId(),

0 commit comments

Comments
 (0)