|
16 | 16 | from opentelemetry.trace import Link, SpanContext, TraceState |
17 | 17 | from testing_support.fixtures import dt_enabled |
18 | 18 | from testing_support.validators.validate_spanlink_spanevent_events import validate_spanlink_or_spanevent_events |
| 19 | +from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics |
19 | 20 |
|
20 | 21 | from newrelic.api.background_task import background_task |
21 | 22 |
|
@@ -162,3 +163,60 @@ def _test(): |
162 | 163 | otel_span.add_event("otelevent", attributes={"key99": "value99", "universe": 42}) |
163 | 164 |
|
164 | 165 | _test() |
| 166 | + |
| 167 | + |
| 168 | +@dt_enabled |
| 169 | +@validate_spanlink_or_spanevent_events( |
| 170 | + count=100, |
| 171 | + exact_intrinsics={"name": "otelevent", "type": "SpanEvent"}, |
| 172 | + expected_intrinsics=["timestamp", "span.id", "trace.id", "name"], |
| 173 | + exact_users={"key1": "value1", "key2": 42}, |
| 174 | +) |
| 175 | +@validate_transaction_metrics( |
| 176 | + "test_spanevent_spanlinks:test_spanevent_events_over_limit.<locals>._test", |
| 177 | + rollup_metrics=[ |
| 178 | + ("Supportability/SpanEvent/Events/Dropped", 3), |
| 179 | + ], |
| 180 | + background_task=True, |
| 181 | +) |
| 182 | +def test_spanevent_events_over_limit(tracer): |
| 183 | + @background_task() |
| 184 | + def _test(): |
| 185 | + with tracer.start_as_current_span("otelspan") as otel_span: |
| 186 | + for _ in range(103): |
| 187 | + otel_span.add_event("otelevent", attributes={"key1": "value1", "key2": 42}) |
| 188 | + |
| 189 | + _test() |
| 190 | + |
| 191 | + |
| 192 | +@dt_enabled |
| 193 | +@validate_spanlink_or_spanevent_events( |
| 194 | + count=100, |
| 195 | + exact_intrinsics={ |
| 196 | + "type": "SpanLink", |
| 197 | + }, |
| 198 | + expected_intrinsics=["timestamp", "id", "trace.id", "linkedSpanId", "linkedTraceId"], |
| 199 | + exact_users={"key1": "value1", "key2": 42}, |
| 200 | +) |
| 201 | +@validate_transaction_metrics( |
| 202 | + "test_spanevent_spanlinks:test_spanlink_events_over_limit.<locals>._test", |
| 203 | + rollup_metrics=[ |
| 204 | + ("Supportability/SpanEvent/Links/Dropped", 3), |
| 205 | + ], |
| 206 | + background_task=True, |
| 207 | +) |
| 208 | +def test_spanlink_events_over_limit(tracer): |
| 209 | + @background_task() |
| 210 | + def _test(): |
| 211 | + with tracer.start_as_current_span("otelspan") as otel_span: |
| 212 | + for incrementer in range(103): |
| 213 | + linked_span_context = SpanContext( |
| 214 | + trace_id=0x1234567890ABCDEF1234567890ABCDEF + incrementer, |
| 215 | + span_id=0x1234567890ABCDEF + incrementer, |
| 216 | + is_remote=True, |
| 217 | + trace_flags=0x01, |
| 218 | + trace_state=TraceState(), |
| 219 | + ) |
| 220 | + otel_span.add_link(linked_span_context, attributes={"key1": "value1", "key2": 42}) |
| 221 | + |
| 222 | + _test() |
0 commit comments