Skip to content
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

Add convenience method setAttribute(Attribute<Long>, int) to SpanBuilder (matching the existing convenience method in Span) #6884

Merged
merged 5 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,18 @@ public interface SpanBuilder {
*/
SpanBuilder setAttribute(String key, double value);

/**
* Sets an attribute to the {@code Span}. If the {@code Span} previously contained a mapping for
* the key, the old value is replaced by the specified value.
Stoyas marked this conversation as resolved.
Show resolved Hide resolved
*
* @param key the key for this attribute.
* @param value the value for this attribute.
* @return this.
*/
default SpanBuilder setAttribute(AttributeKey<Long> key, int value) {
return setAttribute(key, (long) value);
}

/**
* Sets an attribute to the newly created {@code Span}. If {@code SpanBuilder} previously
* contained a mapping for the key, the old value is replaced by the specified value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package io.opentelemetry.api.testing.internal;

import static io.opentelemetry.api.common.AttributeKey.longKey;
import static io.opentelemetry.api.common.AttributeKey.stringKey;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
Expand Down Expand Up @@ -155,6 +156,7 @@ void doNotCrash_NoopImplementation() {
spanBuilder.setStartTimestamp(12345L, TimeUnit.NANOSECONDS);
spanBuilder.setStartTimestamp(Instant.EPOCH);
spanBuilder.setStartTimestamp(null);
spanBuilder.setAttribute(longKey("MyLongAttributeKey"), 123);
assertThat(spanBuilder.startSpan().getSpanContext().isValid()).isFalse();
})
.doesNotThrowAnyException();
Expand Down
4 changes: 3 additions & 1 deletion docs/apidiffs/current_vs_latest/opentelemetry-api.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
Comparing source compatibility of opentelemetry-api-1.45.0-SNAPSHOT.jar against opentelemetry-api-1.44.1.jar
No changes.
*** MODIFIED INTERFACE: PUBLIC ABSTRACT io.opentelemetry.api.trace.SpanBuilder (not serializable)
=== CLASS FILE FORMAT VERSION: 52.0 <- 52.0
+++ NEW METHOD: PUBLIC(+) io.opentelemetry.api.trace.SpanBuilder setAttribute(io.opentelemetry.api.common.AttributeKey<java.lang.Long>, int)
Loading