File tree Expand file tree Collapse file tree 4 files changed +22
-4
lines changed
all/src/main/java/io/opentelemetry/api/trace
testing-internal/src/main/java/io/opentelemetry/api/testing/internal
docs/apidiffs/current_vs_latest
sdk/trace/src/test/java/io/opentelemetry/sdk/trace Expand file tree Collapse file tree 4 files changed +22
-4
lines changed Original file line number Diff line number Diff line change @@ -238,6 +238,18 @@ public interface SpanBuilder {
238238 */
239239 <T > SpanBuilder setAttribute (AttributeKey <T > key , T value );
240240
241+ /**
242+ * Sets an attribute to the newly created {@code Span}. If {@code SpanBuilder} previously
243+ * contained a mapping for the key, the old value is replaced by the specified value.
244+ *
245+ * @param key the key for this attribute.
246+ * @param value the value for this attribute.
247+ * @return this.
248+ */
249+ default SpanBuilder setAttribute (AttributeKey <Long > key , int value ) {
250+ return setAttribute (key , (long ) value );
251+ }
252+
241253 /**
242254 * Sets attributes to the {@link SpanBuilder}. If the {@link SpanBuilder} previously contained a
243255 * mapping for any of the keys, the old values are replaced by the specified values.
Original file line number Diff line number Diff line change 55
66package io .opentelemetry .api .testing .internal ;
77
8+ import static io .opentelemetry .api .common .AttributeKey .longKey ;
89import static io .opentelemetry .api .common .AttributeKey .stringKey ;
910import static org .assertj .core .api .Assertions .assertThat ;
1011import static org .assertj .core .api .Assertions .assertThatCode ;
@@ -155,6 +156,7 @@ void doNotCrash_NoopImplementation() {
155156 spanBuilder .setStartTimestamp (12345L , TimeUnit .NANOSECONDS );
156157 spanBuilder .setStartTimestamp (Instant .EPOCH );
157158 spanBuilder .setStartTimestamp (null );
159+ spanBuilder .setAttribute (longKey ("MyLongAttributeKey" ), 123 );
158160 assertThat (spanBuilder .startSpan ().getSpanContext ().isValid ()).isFalse ();
159161 })
160162 .doesNotThrowAnyException ();
Original file line number Diff line number Diff line change 11Comparing source compatibility of opentelemetry-api-1.45.0-SNAPSHOT.jar against opentelemetry-api-1.44.1.jar
2- No changes.
2+ *** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.trace.SpanBuilder (not serializable)
3+ === CLASS FILE FORMAT VERSION: 52.0 <- 52.0
4+ +++ NEW METHOD: PUBLIC(+) io.opentelemetry.api.trace.SpanBuilder setAttribute(io.opentelemetry.api.common.AttributeKey<java.lang.Long>, int)
Original file line number Diff line number Diff line change @@ -246,19 +246,21 @@ void setAttribute() {
246246 .setAttribute ("long" , 12345L )
247247 .setAttribute ("double" , .12345 )
248248 .setAttribute ("boolean" , true )
249- .setAttribute (stringKey ("stringAttribute" ), "attrvalue" );
249+ .setAttribute (stringKey ("stringAttribute" ), "attrvalue" )
250+ .setAttribute (longKey ("longAttribute" ), 123 );
250251
251252 SdkSpan span = (SdkSpan ) spanBuilder .startSpan ();
252253 try {
253254 SpanData spanData = span .toSpanData ();
254255 Attributes attrs = spanData .getAttributes ();
255- assertThat (attrs .size ()).isEqualTo (5 );
256+ assertThat (attrs .size ()).isEqualTo (6 );
256257 assertThat (attrs .get (stringKey ("string" ))).isEqualTo ("value" );
257258 assertThat (attrs .get (longKey ("long" ))).isEqualTo (12345L );
258259 assertThat (attrs .get (doubleKey ("double" ))).isEqualTo (0.12345 );
259260 assertThat (attrs .get (booleanKey ("boolean" ))).isEqualTo (true );
260261 assertThat (attrs .get (stringKey ("stringAttribute" ))).isEqualTo ("attrvalue" );
261- assertThat (spanData .getTotalAttributeCount ()).isEqualTo (5 );
262+ assertThat (attrs .get (longKey ("longAttribute" ))).isEqualTo (123 );
263+ assertThat (spanData .getTotalAttributeCount ()).isEqualTo (6 );
262264 } finally {
263265 span .end ();
264266 }
You can’t perform that action at this time.
0 commit comments