Skip to content

Start span within function, not outside#11

Merged
deiwin merged 7 commits intomasterfrom
start_span_in_function
Mar 17, 2026
Merged

Start span within function, not outside#11
deiwin merged 7 commits intomasterfrom
start_span_in_function

Conversation

@deiwin
Copy link
Copy Markdown
Contributor

@deiwin deiwin commented Mar 12, 2026

Right now the span was started once, immediately when the wrap
function was called and then ended at the end of each function
invocation. This created weird traces when a) the function wasn't called
immediately and b) when it was called more than once.

With these changes, a new span is started for each invocation at the
beginning of that invocation and ended at the end of that invocation.
This creates traces that match expectations in all scenarios.

It also uses the with_span function to handle the start + stop,
instead of doing this manually, to simplify the code here.

Diff best viewed with whitespace ignored.

@deiwin deiwin requested a review from a team as a code owner March 12, 2026 13:49
@deiwin deiwin force-pushed the start_span_in_function branch from 2dc2dae to 3d8fb69 Compare March 12, 2026 14:27
deiwin added 3 commits March 12, 2026 16:27
Right now the span was started once, immediately when the `wrap`
function was called and then ended at the end of each function
invocation. This created weird traces when a) the function wasn't called
immediately and b) when it was called more than once.

With these changes, a new span is started for each invocation at the
beginning of that invocation and ended at the end of that invocation.
This creates traces that match expectations in all scenarios.

It also uses the `with_span` function to handle the start + stop,
instead of doing this manually, to simplify the code here.

The dependency versions were increased slightly because the
`OpenTelemetry.Tracer.record_exception/1` shorthand was [added in
v1.1.0][1].

Diff best viewed with whitespace ignored.

[1]: open-telemetry/opentelemetry-erlang#410
We have the message available there, might as well use it.
@deiwin deiwin force-pushed the start_span_in_function branch from 3d8fb69 to 4294dc2 Compare March 12, 2026 14:27
deiwin added 2 commits March 12, 2026 16:38
The v2 GitHub actions are no longer supported. Upgrade to latest.

Also upgrades one of the jobs to run against the latest Elixir & OTP
versions. The other one keeps running against the oldest supported
versions.
The `erlef/setup-beam@v1` action fails with the following error:
> Error: Requested loose Erlang/OTP version (23.0) not found in version list

Based on [their readme][1], the earliest supported OTP version for the
latest Ubuntu is 24.3. And OTP 24 support was added in Elixir 1.12. So
we need to bump the oldest supported version to run these tests.

[1]: https://github.com/erlef/setup-beam?tab=readme-ov-file#compatibility-between-operating-system-and-erlangotp
@deiwin deiwin force-pushed the start_span_in_function branch from d8979e2 to 0e829e0 Compare March 12, 2026 14:44
deiwin added 2 commits March 12, 2026 16:47
It was giving the following warning without this:
```
warning: Range.new/2 and first..last default to a step of -1 when last < first. Use Range.new(first, last, -1) or first..last//-1, or pass 1 if that was your intention
```
It was failing with `:prettypr` being undefined. After the upgrade
`mix dialyxir` works as expected.
@deiwin deiwin requested a review from indrekj March 12, 2026 15:48
@deiwin deiwin merged commit a0398a8 into master Mar 17, 2026
7 checks passed
@deiwin deiwin deleted the start_span_in_function branch March 17, 2026 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants