Skip to content

Add attributes API - #1007

Merged
giortzisg merged 4 commits into
masterfrom
feat/attributes
May 7, 2025
Merged

Add attributes API#1007
giortzisg merged 4 commits into
masterfrom
feat/attributes

Conversation

@giortzisg

@giortzisg giortzisg commented May 5, 2025

Copy link
Copy Markdown
Contributor

Description

Implement the attributes API for typesafe values to set on spans.

Usage example

// creating [attribute.Values]
strValue := attribute.StringValue("value")
intValue := attribute.IntValue(42)
int64Value := attribute.Int64Value(42)
float64Value := attribute.Float64Value(42.1)

// accessing them
strValue.AsString()
intValue.AsInt64()

// creating [attribute.Builder]
attribute.String("key", "value")
attribute.Int("key.int", 42)

// usage example with SetData 
span.SetData("key",  attribute.StringValue("value"))

Improvements

allow SetData to handle a map[string]Value for providing easier access to the span values and also ensure that we support all values provided on SetData. An example of how that would look like is something like:

span.SetData(
  attribute.String("key", "value"),
  attribute.Bool("key.bool", true),
  attribute.Int("key.int", 42),
  attribute.Int64("key.int64", 17),
  attribute.Float64("key.float", 42.1),
)

@giortzisg giortzisg added Go SDK Feature Issue type labels May 5, 2025
@giortzisg
giortzisg requested a review from cleptric May 5, 2025 14:14
@giortzisg giortzisg self-assigned this May 5, 2025
@codecov

codecov Bot commented May 5, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 89.32039% with 11 lines in your changes missing coverage. Please review.

Project coverage is 84.05%. Comparing base (c7d162c) to head (5cdc4db).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
attribute/value.go 86.48% 10 Missing ⚠️
attribute/rawhelpers.go 94.11% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1007      +/-   ##
==========================================
+ Coverage   84.00%   84.05%   +0.04%     
==========================================
  Files          50       53       +3     
  Lines        5171     5274     +103     
==========================================
+ Hits         4344     4433      +89     
- Misses        673      686      +13     
- Partials      154      155       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread attribute/value.go Outdated
Comment on lines +131 to +132
// Emit returns a string representation of Value's data.
func (v Value) Emit() string {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we should implement Emit() orString(), but kept Emit same as otel. However for me it's more natural to be able to get the value directly with fmt.Println(v.Value) rather than v.Value.Emit()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, let's change it.

@giortzisg
giortzisg merged commit 021ccc1 into master May 7, 2025
@giortzisg
giortzisg deleted the feat/attributes branch May 7, 2025 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature Issue type Go SDK

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants