Skip to content

Commit d6b9524

Browse files
committed
Add environment to transaction
1 parent 96d50e6 commit d6b9524

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/sentry/transaction.ex

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
defmodule Sentry.Transaction do
22
@type t() :: %__MODULE__{}
33

4-
alias Sentry.{UUID}
4+
alias Sentry.{Config, UUID}
55

66
defstruct [
77
:event_id,
8+
:environment,
89
:start_timestamp,
910
:timestamp,
1011
:transaction,
@@ -18,7 +19,12 @@ defmodule Sentry.Transaction do
1819
]
1920

2021
def new(attrs) do
21-
struct(__MODULE__, Map.put(attrs, :event_id, UUID.uuid4_hex()))
22+
struct(
23+
__MODULE__,
24+
attrs
25+
|> Map.put(:event_id, UUID.uuid4_hex())
26+
|> Map.put(:environment, Config.environment_name())
27+
)
2228
end
2329

2430
# Used to then encode the returned map to JSON.

test/sentry/opentelemetry/span_processor_test.exs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ defmodule Sentry.Opentelemetry.SpanProcessorTest do
4444

4545
assert [%Sentry.Transaction{} = transaction] = Sentry.Test.pop_sentry_transactions()
4646

47+
assert transaction.environment == "test"
48+
assert transaction.type == "transaction"
4749
assert_valid_iso8601(transaction.timestamp)
4850
assert_valid_iso8601(transaction.start_timestamp)
4951
assert transaction.timestamp > transaction.start_timestamp
@@ -64,6 +66,9 @@ defmodule Sentry.Opentelemetry.SpanProcessorTest do
6466
TestEndpoint.instrumented_function()
6567

6668
assert [%Sentry.Transaction{} = transaction] = Sentry.Test.pop_sentry_transactions()
69+
70+
assert transaction.environment == "test"
71+
assert transaction.type == "transaction"
6772
assert_valid_iso8601(transaction.timestamp)
6873
assert_valid_iso8601(transaction.start_timestamp)
6974
assert transaction.timestamp > transaction.start_timestamp

0 commit comments

Comments
 (0)