Skip to content

Commit b099880

Browse files
Implement outcome for transactions & spans (#1613)
Co-authored-by: eyalkoren <[email protected]>
1 parent e266b98 commit b099880

File tree

112 files changed

+2089
-641
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

112 files changed

+2089
-641
lines changed

apm-agent-api/src/main/java/co/elastic/apm/api/AbstractSpanImpl.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,83 +63,87 @@ public Span startSpan() {
6363
}
6464

6565
public void doSetStartTimestamp(long epochMicros) {
66-
// co.elastic.apm.agent.plugin.api.AbstractSpanInstrumentation$SetStartTimestampInstrumentation
66+
// co.elastic.apm.agent.pluginapi.AbstractSpanInstrumentation$SetStartTimestampInstrumentation
67+
}
68+
69+
public void doSetOutcome(Outcome outcome) {
70+
// co.elastic.apm.agent.pluginapi.AbstractSpanInstrumentation.SetOutcomeInstrumentation
6771
}
6872

6973
private Object doCreateSpan() {
70-
// co.elastic.apm.agent.plugin.api.AbstractSpanInstrumentation$DoCreateSpanInstrumentation.doCreateSpan
74+
// co.elastic.apm.agent.pluginapi.AbstractSpanInstrumentation$DoCreateSpanInstrumentation.doCreateSpan
7175
return null;
7276
}
7377

7478
void doSetName(String name) {
75-
// co.elastic.apm.agent.plugin.api.AbstractSpanInstrumentation$SetNameInstrumentation.doSetName
79+
// co.elastic.apm.agent.pluginapi.AbstractSpanInstrumentation$SetNameInstrumentation.doSetName
7680
}
7781

7882
void doSetType(String type) {
79-
// co.elastic.apm.agent.plugin.api.AbstractSpanInstrumentation$SetTypeInstrumentation.doSetType
83+
// co.elastic.apm.agent.pluginapi.AbstractSpanInstrumentation$SetTypeInstrumentation.doSetType
8084
}
8185

8286
private void doSetTypes(Object span, String type, @Nullable String subtype, @Nullable String action) {
83-
// co.elastic.apm.agent.plugin.api.AbstractSpanInstrumentation$SetTypesInstrumentation.doSetType
87+
// co.elastic.apm.agent.pluginapi.AbstractSpanInstrumentation$SetTypesInstrumentation.doSetType
8488
}
8589

8690
// keep for backwards compatibility reasons
8791
@Deprecated
8892
void doAddTag(String key, String value) {
89-
// co.elastic.apm.agent.plugin.api.AbstractSpanInstrumentation$AddStringLabelInstrumentation
93+
// co.elastic.apm.agent.pluginapi.AbstractSpanInstrumentation$AddStringLabelInstrumentation
9094
}
9195

9296
void doAddStringLabel(String key, String value) {
93-
// co.elastic.apm.agent.plugin.api.AbstractSpanInstrumentation$AddStringLabelInstrumentation
97+
// co.elastic.apm.agent.pluginapi.AbstractSpanInstrumentation$AddStringLabelInstrumentation
9498
}
9599

96100
void doAddNumberLabel(String key, Number value) {
97101
// co.elastic.apm.agent.plugin.api.AbstractSpanInstrumentation$AddNumberLabelInstrumentation
98102
}
99103

100104
void doAddBooleanLabel(String key, Boolean value) {
101-
// co.elastic.apm.agent.plugin.api.AbstractSpanInstrumentation$AddBooleanTagInstrumentation
105+
// co.elastic.apm.agent.pluginapi.AbstractSpanInstrumentation$AddBooleanTagInstrumentation
102106
}
103107

104108
@Override
105109
public void end() {
106-
// co.elastic.apm.agent.plugin.api.AbstractSpanInstrumentation$EndInstrumentation
110+
// co.elastic.apm.agent.pluginapi.AbstractSpanInstrumentation$EndInstrumentation
107111
}
108112

109113
@Override
110114
public void end(long epochMicros) {
111-
// co.elastic.apm.agent.plugin.api.AbstractSpanInstrumentation$EndWithTimestampInstrumentation
115+
// co.elastic.apm.agent.pluginapi.AbstractSpanInstrumentation$EndWithTimestampInstrumentation
112116
}
113117

114118
@Override
115119
public String captureException(Throwable throwable) {
116-
// co.elastic.apm.agent.plugin.api.AbstractSpanInstrumentation.CaptureExceptionInstrumentation
120+
// co.elastic.apm.agent.pluginapi.AbstractSpanInstrumentation.CaptureExceptionInstrumentation
117121
return "";
118122
}
119123

120124
@Nonnull
121125
@Override
122126
public String getId() {
123-
// co.elastic.apm.agent.plugin.api.AbstractSpanInstrumentation.GetIdInstrumentation
127+
// co.elastic.apm.agent.pluginapi.AbstractSpanInstrumentation.GetIdInstrumentation
124128
return "";
125129
}
126130

127131
@Nonnull
128132
@Override
129133
public String getTraceId() {
130-
// co.elastic.apm.agent.plugin.api.AbstractSpanInstrumentation.GetTraceIdInstrumentation
134+
// co.elastic.apm.agent.pluginapi.AbstractSpanInstrumentation.GetTraceIdInstrumentation
131135
return "";
132136
}
133137

134138
@Override
135139
public Scope activate() {
136-
// co.elastic.apm.agent.plugin.api.AbstractSpanInstrumentation.ActivateInstrumentation
140+
// co.elastic.apm.agent.pluginapi.AbstractSpanInstrumentation.ActivateInstrumentation
137141
return new ScopeImpl(span);
138142
}
139143

140144
@Override
141145
public boolean isSampled() {
142-
// co.elastic.apm.agent.plugin.api.AbstractSpanInstrumentation.IsSampledInstrumentation
146+
// co.elastic.apm.agent.pluginapi.AbstractSpanInstrumentation.IsSampledInstrumentation
143147
return false;
144148
}
145149

@@ -149,6 +153,6 @@ public void injectTraceHeaders(HeaderInjector headerInjector) {
149153
}
150154

151155
private void doInjectTraceHeaders(MethodHandle addHeader, HeaderInjector headerInjector) {
152-
// co.elastic.apm.agent.plugin.api.AbstractSpanInstrumentation.InjectTraceHeadersInstrumentation
156+
// co.elastic.apm.agent.pluginapi.AbstractSpanInstrumentation.InjectTraceHeadersInstrumentation
153157
}
154158
}

apm-agent-api/src/main/java/co/elastic/apm/api/ElasticApm.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
* the Apache License, Version 2.0 (the "License"); you may
1212
* not use this file except in compliance with the License.
1313
* You may obtain a copy of the License at
14-
*
14+
*
1515
* http://www.apache.org/licenses/LICENSE-2.0
16-
*
16+
*
1717
* Unless required by applicable law or agreed to in writing,
1818
* software distributed under the License is distributed on an
1919
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -169,7 +169,7 @@ public static Transaction startTransactionWithRemoteParent(HeaderExtractor heade
169169

170170
private static Object doStartTransactionWithRemoteParentFunction(MethodHandle getFirstHeader, HeaderExtractor headerExtractor,
171171
MethodHandle getAllHeaders, HeadersExtractor headersExtractor) {
172-
// co.elastic.apm.agent.plugin.api.ElasticApmApiInstrumentation.StartTransactionWithRemoteParentInstrumentation
172+
// co.elastic.apm.agent.pluginapi.ElasticApmApiInstrumentation.StartTransactionWithRemoteParentInstrumentation
173173
return null;
174174
}
175175

apm-agent-api/src/main/java/co/elastic/apm/api/NoopSpan.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public void end(long epochMicros) {
103103

104104
@Override
105105
public String captureException(Throwable throwable) {
106-
// co.elastic.apm.agent.plugin.api.CaptureExceptionInstrumentation
106+
// co.elastic.apm.agent.pluginapi.CaptureExceptionInstrumentation
107107
return "";
108108
}
109109

@@ -132,7 +132,8 @@ public boolean isSampled() {
132132
@Nonnull
133133
@Override
134134
public Span createSpan() {
135-
return INSTANCE;
135+
// noop
136+
return this;
136137
}
137138

138139
@Nonnull
@@ -144,12 +145,20 @@ public Span startSpan(String type, @Nullable String subtype, @Nullable String ac
144145
@Nonnull
145146
@Override
146147
public Span startSpan() {
147-
return INSTANCE;
148+
// noop
149+
return this;
148150
}
149151

150152
@Override
151153
public Span setStartTimestamp(long epochMicros) {
152-
return INSTANCE;
154+
// noop
155+
return this;
156+
}
157+
158+
@Override
159+
public Span setOutcome(Outcome outcome) {
160+
// noop
161+
return this;
153162
}
154163

155164
@Override

apm-agent-api/src/main/java/co/elastic/apm/api/NoopTransaction.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public void end(long epochMicros) {
134134

135135
@Override
136136
public String captureException(Throwable throwable) {
137-
// co.elastic.apm.agent.plugin.api.CaptureExceptionInstrumentation
137+
// co.elastic.apm.agent.pluginapi.CaptureExceptionInstrumentation
138138
return "";
139139
}
140140

@@ -189,6 +189,12 @@ public Transaction setStartTimestamp(long epochMicros) {
189189
return this;
190190
}
191191

192+
@Override
193+
public Transaction setOutcome(Outcome outcome) {
194+
195+
return this;
196+
}
197+
192198
@Override
193199
public void injectTraceHeaders(HeaderInjector headerInjector) {
194200
// noop
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*-
2+
* #%L
3+
* Elastic APM Java agent
4+
* %%
5+
* Copyright (C) 2018 - 2021 Elastic and contributors
6+
* %%
7+
* Licensed to Elasticsearch B.V. under one or more contributor
8+
* license agreements. See the NOTICE file distributed with
9+
* this work for additional information regarding copyright
10+
* ownership. Elasticsearch B.V. licenses this file to you under
11+
* the Apache License, Version 2.0 (the "License"); you may
12+
* not use this file except in compliance with the License.
13+
* You may obtain a copy of the License at
14+
*
15+
* http://www.apache.org/licenses/LICENSE-2.0
16+
*
17+
* Unless required by applicable law or agreed to in writing,
18+
* software distributed under the License is distributed on an
19+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20+
* KIND, either express or implied. See the License for the
21+
* specific language governing permissions and limitations
22+
* under the License.
23+
* #L%
24+
*/
25+
package co.elastic.apm.api;
26+
27+
/**
28+
* Outcome of Transaction or Span
29+
*/
30+
public enum Outcome {
31+
SUCCESS,
32+
FAILURE,
33+
UNKNOWN
34+
}

apm-agent-api/src/main/java/co/elastic/apm/api/ScopeImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ class ScopeImpl implements Scope {
3939

4040
@Override
4141
public void close() {
42-
// co.elastic.apm.agent.plugin.api.ApiScopeInstrumentation
42+
// co.elastic.apm.agent.pluginapi.ApiScopeInstrumentation
4343
}
4444
}

apm-agent-api/src/main/java/co/elastic/apm/api/Span.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,20 @@ public interface Span {
8383
Span addLabel(String key, String value);
8484

8585
/**
86-
* @deprecated use {@link #setLabel(String, Number)}
87-
*
8886
* @param key The label key.
8987
* @param value The label value.
9088
* @since 1.5.0, APM Server 6.7
89+
* @deprecated use {@link #setLabel(String, Number)}
9190
*/
9291
@Nonnull
9392
@Deprecated
9493
Span addLabel(String key, Number value);
9594

9695
/**
97-
* @deprecated use {@link #setLabel(String, boolean)}
98-
*
9996
* @param key The label key.
10097
* @param value The label value.
10198
* @since 1.5.0, APM Server 6.7
99+
* @deprecated use {@link #setLabel(String, boolean)}
102100
*/
103101
@Nonnull
104102
@Deprecated
@@ -208,6 +206,15 @@ public interface Span {
208206
*/
209207
Span setStartTimestamp(long epochMicros);
210208

209+
/**
210+
* Sets the outcome of this event
211+
*
212+
* @param outcome {@link Outcome#SUCCESS} to indicate success, {@link Outcome#FAILURE} for failure,
213+
* {@link Outcome#UNKNOWN} to indicate unknown outcome
214+
* @return this
215+
*/
216+
Span setOutcome(Outcome outcome);
217+
211218
/**
212219
* NOTE: THIS METHOD IS DEPRECATED AND WILL BE REMOVED IN VERSION 2.0.
213220
* Instead, start a new span through {@link #startSpan()} or {@link #startSpan(String, String, String)}.
@@ -255,9 +262,9 @@ public interface Span {
255262
* (underscore) character.
256263
* </p>
257264
*
258-
* @param type The general type of the new span
259-
* @param subtype The subtype of the new span
260-
* @param action The action related to the new span
265+
* @param type The general type of the new span
266+
* @param subtype The subtype of the new span
267+
* @param action The action related to the new span
261268
* @return the started span, never {@code null}
262269
*/
263270
@Nonnull

apm-agent-api/src/main/java/co/elastic/apm/api/SpanImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,9 @@ public Span setStartTimestamp(long epochMicros) {
111111
return this;
112112
}
113113

114+
@Override
115+
public Span setOutcome(Outcome outcome) {
116+
doSetOutcome(outcome);
117+
return this;
118+
}
114119
}

apm-agent-api/src/main/java/co/elastic/apm/api/Transaction.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,16 @@ public interface Transaction extends Span {
192192
@Override
193193
Transaction setStartTimestamp(long epochMicros);
194194

195+
/**
196+
* Sets the transaction outcome
197+
*
198+
* @param outcome {@link Outcome#SUCCESS} to indicate success, {@link Outcome#FAILURE} for failure,
199+
* {@link Outcome#UNKNOWN} to indicate unknown outcome
200+
* @return this
201+
*/
202+
203+
Transaction setOutcome(Outcome outcome);
204+
195205
/**
196206
* End tracking the transaction.
197207
* <p>

apm-agent-api/src/main/java/co/elastic/apm/api/TransactionImpl.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,40 +110,40 @@ public Transaction setLabel(String key, boolean value) {
110110
@Nonnull
111111
@Override
112112
public Transaction addCustomContext(String key, String value) {
113-
// co.elastic.apm.agent.plugin.api.TransactionInstrumentation$AddCustomContextInstrumentation
113+
// co.elastic.apm.agent.pluginapi.TransactionInstrumentation$AddCustomContextInstrumentation
114114
return this;
115115
}
116116

117117
@Nonnull
118118
@Override
119119
public Transaction addCustomContext(String key, Number value) {
120-
// co.elastic.apm.agent.plugin.api.TransactionInstrumentation$AddCustomContextInstrumentation
120+
// co.elastic.apm.agent.pluginapi.TransactionInstrumentation$AddCustomContextInstrumentation
121121
return this;
122122
}
123123

124124
@Nonnull
125125
@Override
126126
public Transaction addCustomContext(String key, boolean value) {
127-
// co.elastic.apm.agent.plugin.api.TransactionInstrumentation$AddCustomContextInstrumentation
127+
// co.elastic.apm.agent.pluginapi.TransactionInstrumentation$AddCustomContextInstrumentation
128128
return this;
129129
}
130130

131131
@Override
132132
public Transaction setUser(String id, String email, String username) {
133-
// co.elastic.apm.agent.plugin.api.TransactionInstrumentation$SetUserInstrumentation.setUser
133+
// co.elastic.apm.agent.pluginapi.TransactionInstrumentation$SetUserInstrumentation.setUser
134134
return this;
135135
}
136136

137137
@Override
138138
public Transaction setResult(String result) {
139-
// co.elastic.apm.agent.plugin.api.TransactionInstrumentation.SetResultInstrumentation
139+
// co.elastic.apm.agent.pluginapi.TransactionInstrumentation.SetResultInstrumentation
140140
return this;
141141
}
142142

143143
@Nonnull
144144
@Override
145145
public String ensureParentId() {
146-
// co.elastic.apm.agent.plugin.api.TransactionInstrumentation.EnsureParentIdInstrumentation
146+
// co.elastic.apm.agent.pluginapi.TransactionInstrumentation.EnsureParentIdInstrumentation
147147
return "";
148148
}
149149

@@ -153,4 +153,9 @@ public Transaction setStartTimestamp(long epochMicros) {
153153
return this;
154154
}
155155

156+
@Override
157+
public Transaction setOutcome(Outcome outcome) {
158+
doSetOutcome(outcome);
159+
return this;
160+
}
156161
}

0 commit comments

Comments
 (0)