1
0
mirror of https://github.com/open-telemetry/opentelemetry-go.git synced 2026-06-03 18:35:08 +02:00
Files
opentelemetry-go/bridge/opencensus/internal/span.go
T
renovate[bot] cf2a4a180f chore(deps): update module mvdan.cc/gofumpt to v0.10.0 (#8304)
This PR contains the following updates:

| Package | Change |
[Age](https://docs.renovatebot.com/merge-confidence/) |
[Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [mvdan.cc/gofumpt](https://redirect.github.com/mvdan/gofumpt) |
`v0.9.2` → `v0.10.0` |
![age](https://developer.mend.io/api/mc/badges/age/go/mvdan.cc%2fgofumpt/v0.10.0?slim=true)
|
![confidence](https://developer.mend.io/api/mc/badges/confidence/go/mvdan.cc%2fgofumpt/v0.9.2/v0.10.0?slim=true)
|

---

### Release Notes

<details>
<summary>mvdan/gofumpt (mvdan.cc/gofumpt)</summary>

###
[`v0.10.0`](https://redirect.github.com/mvdan/gofumpt/blob/HEAD/CHANGELOG.md#v0100---2026-05-04)

[Compare
Source](https://redirect.github.com/mvdan/gofumpt/compare/v0.9.2...v0.10.0)

This release is based on Go 1.26's gofmt, and requires Go 1.25 or later.

A new rule is introduced to drop unnecessary parentheses around
expressions
where the inner expression is unambiguous on its own, such as `f((3))`.
Parentheses are kept where they are useful, such as on binary
expressions. See
[#&#8203;44](https://redirect.github.com/mvdan/gofumpt/issues/44).

A new rule is introduced to require multi-line function calls to match
the opening and closing parenthesis in terms of the use of newlines. See
[#&#8203;74](https://redirect.github.com/mvdan/gofumpt/issues/74).

The `-extra` flag now accepts a comma-separated list of rule names to
enable
individual extra rules, rather than enabling all of them at once. See
[#&#8203;339](https://redirect.github.com/mvdan/gofumpt/issues/339).

The following changes are included as well:

- Avoid crashing on `go.mod` files without a `module` directive -
[#&#8203;350](https://redirect.github.com/mvdan/gofumpt/issues/350)
- Avoid failing when an ignored directory cannot be read -
[#&#8203;351](https://redirect.github.com/mvdan/gofumpt/issues/351)
- Avoid prefixing more kinds of commented-out Go code with spaces -
[#&#8203;230](https://redirect.github.com/mvdan/gofumpt/issues/230)
- Avoid prefixing a shebang comment with a space -
[#&#8203;237](https://redirect.github.com/mvdan/gofumpt/issues/237)
- Narrow the newlines on assignments rule to ignore complex cases -
[#&#8203;354](https://redirect.github.com/mvdan/gofumpt/issues/354)
- Fix three bugs which caused a second gofumpt run to make changes -
[#&#8203;132](https://redirect.github.com/mvdan/gofumpt/issues/132),
[#&#8203;345](https://redirect.github.com/mvdan/gofumpt/issues/345)

</details>

---

### Configuration

📅 **Schedule**: (UTC)

- Branch creation
  - At any time (no schedule defined)
- Automerge
  - At any time (no schedule defined)

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/).
View the [repository job
log](https://developer.mend.io/github/open-telemetry/opentelemetry-go).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xNTkuMiIsInVwZGF0ZWRJblZlciI6IjQzLjE1OS4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiIsImxhYmVscyI6WyJTa2lwIENoYW5nZWxvZyIsImRlcGVuZGVuY2llcyJdfQ==-->

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Tyler Yahn <codingalias@gmail.com>
2026-05-08 12:50:12 -07:00

137 lines
4.1 KiB
Go

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package internal // import "go.opentelemetry.io/otel/bridge/opencensus/internal"
import (
"fmt"
octrace "go.opencensus.io/trace"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/bridge/opencensus/internal/oc2otel"
"go.opentelemetry.io/otel/bridge/opencensus/internal/otel2oc"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
)
const (
// MessageSendEvent is the name of the message send event.
MessageSendEvent = "message send"
// MessageReceiveEvent is the name of the message receive event.
MessageReceiveEvent = "message receive"
)
var (
// UncompressedKey is used for the uncompressed byte size attribute.
UncompressedKey = attribute.Key("uncompressed byte size")
// CompressedKey is used for the compressed byte size attribute.
CompressedKey = attribute.Key("compressed byte size")
)
// Span is an OpenCensus SpanInterface wrapper for an OpenTelemetry Span.
type Span struct {
otelSpan trace.Span
}
// NewSpan returns an OpenCensus Span wrapping an OpenTelemetry Span.
func NewSpan(s trace.Span) *octrace.Span {
return octrace.NewSpan(&Span{otelSpan: s})
}
// IsRecordingEvents reports whether events are being recorded for this span.
func (s *Span) IsRecordingEvents() bool {
return s.otelSpan.IsRecording()
}
// End ends this span.
func (s *Span) End() {
s.otelSpan.End()
}
// SpanContext returns the SpanContext of this span.
func (s *Span) SpanContext() octrace.SpanContext {
return otel2oc.SpanContext(s.otelSpan.SpanContext())
}
// SetName sets the name of this span, if it is recording events.
func (s *Span) SetName(name string) {
s.otelSpan.SetName(name)
}
// SetStatus sets the status of this span, if it is recording events.
func (s *Span) SetStatus(status octrace.Status) {
s.otelSpan.SetStatus(codes.Code(max(0, status.Code)), status.Message) // nolint:gosec // Overflow checked.
}
// AddAttributes sets attributes in this span.
func (s *Span) AddAttributes(attributes ...octrace.Attribute) {
s.otelSpan.SetAttributes(oc2otel.Attributes(attributes)...)
}
// Annotate adds an annotation with attributes to this span.
func (s *Span) Annotate(attributes []octrace.Attribute, str string) {
s.otelSpan.AddEvent(str, trace.WithAttributes(oc2otel.Attributes(attributes)...))
}
// Annotatef adds a formatted annotation with attributes to this span.
func (s *Span) Annotatef(attributes []octrace.Attribute, format string, a ...any) {
s.Annotate(attributes, fmt.Sprintf(format, a...))
}
// AddMessageSendEvent adds a message send event to this span.
func (s *Span) AddMessageSendEvent(_, uncompressedByteSize, compressedByteSize int64) {
s.otelSpan.AddEvent(
MessageSendEvent,
trace.WithAttributes(
attribute.KeyValue{
Key: UncompressedKey,
Value: attribute.Int64Value(uncompressedByteSize),
},
attribute.KeyValue{
Key: CompressedKey,
Value: attribute.Int64Value(compressedByteSize),
},
),
)
}
// AddMessageReceiveEvent adds a message receive event to this span.
func (s *Span) AddMessageReceiveEvent(_, uncompressedByteSize, compressedByteSize int64) {
s.otelSpan.AddEvent(
MessageReceiveEvent,
trace.WithAttributes(
attribute.KeyValue{
Key: UncompressedKey,
Value: attribute.Int64Value(uncompressedByteSize),
},
attribute.KeyValue{
Key: CompressedKey,
Value: attribute.Int64Value(compressedByteSize),
},
),
)
}
// AddLink adds a link to this span.
// This drops the OpenCensus LinkType because there is no such concept in OpenTelemetry.
func (s *Span) AddLink(l octrace.Link) {
s.otelSpan.AddLink(trace.Link{
SpanContext: trace.NewSpanContext(trace.SpanContextConfig{
TraceID: trace.TraceID(l.TraceID),
SpanID: trace.SpanID(l.SpanID),
// We don't know if this was sampled or not.
// Mark it as sampled, since sampled means
// "the caller may have recorded trace data":
// https://www.w3.org/TR/trace-context/#sampled-flag
TraceFlags: trace.FlagsSampled,
}),
Attributes: oc2otel.AttributesFromMap(l.Attributes),
})
}
// String prints a string representation of this span.
func (s *Span) String() string {
return "span " + s.otelSpan.SpanContext().SpanID().String()
}