Commit 7637378
authored
[APMSVLS-197] Add check to extract trace context present within event.request.headers (#1011)
# [APMSVLS-197] feat: Add check to extract trace context from event.request.headers
## Overview
This PR adds automatic trace context extraction from `event.request.headers` for AppSync integration scenarios. This eliminates the need for customers to use customized extractors for RUM → AppSync → Lambda resolver flows where RUM-injected trace context is nested under `event["request"]["headers"]`.
## Problem
Previously, trace context from RUM was not propagated through AppSync to Lambda resolvers because the extension only checked:
1. Trigger-specific headers (via span inferrer)
2. `event.headers` (top-level event headers)
3. Request headers (HTTP request headers)
For AppSync, the trace context is nested under `event.request.headers`, which was not checked, causing traces to break at the AppSync boundary.
## Solution
Added a step that checks `event.request.headers` after all other trace context sources have been attempted.
## Trace Examples
### Before
Without this change, trace context is lost at the AppSync boundary:
[Trace showing broken propagation through AppSync](https://ddserverless.datadoghq.com/apm/trace/5616290163800553628?graphType=waterfall&shouldShowLegend=true&spanID=5616290163800553628&timeHint=1769698078685.9998&traceQuery=)
[Log showing the passed header value for x-datadog-trace-id does not align with the given trace_id](https://ddserverless.datadoghq.com/logs?query=%40lambda.request_id%3A%28cba225c5-7b76-45d8-9a43-86df9031687f%29%20OR%20trace_id%3A5616290163800553628&agg_m=count&agg_m_source=base&agg_t=count&cols=host%2Cservice&event=AwAAAZwKObH6tpUUmwAAABhBWndLT2JqNEFBQWpWdUZHSkF5YzFRQXgAAAAkZjE5YzBhNDQtYjE3Zi00YjljLTk2NzMtNWY2NzI2OTc2MDlmAA2mrg&fromUser=true&messageDisplay=inline&refresh_mode=paused&storage=flex_tier&stream_sort=desc&viz=stream&from_ts=1769697078981&to_ts=1769699079405&live=false)
Flow: `RUM → AppSync → Lambda` (trace ID not propagated)
### After
With this change, trace context is properly extracted and propagated:
[Trace showing successful propagation through AppSync](https://ddserverless.datadoghq.com/apm/trace/12345?graphType=waterfall&shouldShowLegend=true&spanID=7582932037133874185&timeHint=1769698399447&traceQuery=)
Flow: `RUM → AppSync → Lambda resolver` (trace continues using value within x-datadog-trace-id)
## Testing
### Unit Tests
Added 10 unit tests covering:
- Extraction from `event.request.headers` with Datadog headers
- Extraction from `event.request.headers` with W3C TraceContext headers
- Edge cases (missing headers, empty objects, invalid data)
Run tests with:
```bash
cargo test test_extract_span_context -- --nocapture
```
[APMSVLS-197]: https://datadoghq.atlassian.net/browse/APMSVLS-197?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
Co-authored-by: david.ogbureke <[email protected]>1 parent d052e8d commit 7637378
1 file changed
+76
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1076 | 1076 | | |
1077 | 1077 | | |
1078 | 1078 | | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
1079 | 1088 | | |
1080 | 1089 | | |
1081 | 1090 | | |
| |||
1851 | 1860 | | |
1852 | 1861 | | |
1853 | 1862 | | |
| 1863 | + | |
| 1864 | + | |
| 1865 | + | |
| 1866 | + | |
| 1867 | + | |
| 1868 | + | |
| 1869 | + | |
| 1870 | + | |
| 1871 | + | |
| 1872 | + | |
| 1873 | + | |
| 1874 | + | |
| 1875 | + | |
| 1876 | + | |
| 1877 | + | |
| 1878 | + | |
| 1879 | + | |
| 1880 | + | |
| 1881 | + | |
| 1882 | + | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
| 1888 | + | |
| 1889 | + | |
| 1890 | + | |
| 1891 | + | |
| 1892 | + | |
| 1893 | + | |
| 1894 | + | |
| 1895 | + | |
| 1896 | + | |
| 1897 | + | |
| 1898 | + | |
| 1899 | + | |
| 1900 | + | |
| 1901 | + | |
| 1902 | + | |
| 1903 | + | |
| 1904 | + | |
| 1905 | + | |
| 1906 | + | |
| 1907 | + | |
| 1908 | + | |
| 1909 | + | |
| 1910 | + | |
| 1911 | + | |
| 1912 | + | |
| 1913 | + | |
| 1914 | + | |
| 1915 | + | |
| 1916 | + | |
| 1917 | + | |
| 1918 | + | |
| 1919 | + | |
| 1920 | + | |
| 1921 | + | |
| 1922 | + | |
| 1923 | + | |
| 1924 | + | |
| 1925 | + | |
| 1926 | + | |
| 1927 | + | |
| 1928 | + | |
| 1929 | + | |
1854 | 1930 | | |
0 commit comments