@@ -28,19 +28,21 @@ void DatadogContext::on_change_block(ngx_http_request_t *request,
28
28
29
29
// This is a new subrequest, so add a RequestTracing for it.
30
30
// TODO: Should `active_span` be `request_span` instead?
31
- traces_.emplace_back (request, core_loc_conf, loc_conf, &traces_[0 ].active_span ());
31
+ traces_.emplace_back (request, core_loc_conf, loc_conf,
32
+ &traces_[0 ].active_span ());
32
33
}
33
34
34
35
void DatadogContext::on_log_request (ngx_http_request_t *request) {
35
36
auto trace = find_trace (request);
36
37
if (trace == nullptr ) {
37
- throw std::runtime_error{" on_log_request failed: could not find request trace" };
38
+ throw std::runtime_error{
39
+ " on_log_request failed: could not find request trace" };
38
40
}
39
41
trace->on_log_request ();
40
42
}
41
43
42
- ngx_str_t DatadogContext::lookup_propagation_header_variable_value (ngx_http_request_t *request,
43
- std::string_view key) {
44
+ ngx_str_t DatadogContext::lookup_propagation_header_variable_value (
45
+ ngx_http_request_t *request, std::string_view key) {
44
46
auto trace = find_trace (request);
45
47
if (trace == nullptr ) {
46
48
throw std::runtime_error{
@@ -50,11 +52,12 @@ ngx_str_t DatadogContext::lookup_propagation_header_variable_value(ngx_http_requ
50
52
return trace->lookup_propagation_header_variable_value (key);
51
53
}
52
54
53
- ngx_str_t DatadogContext::lookup_span_variable_value (ngx_http_request_t *request,
54
- std::string_view key) {
55
+ ngx_str_t DatadogContext::lookup_span_variable_value (
56
+ ngx_http_request_t *request, std::string_view key) {
55
57
auto trace = find_trace (request);
56
58
if (trace == nullptr ) {
57
- throw std::runtime_error{" lookup_span_variable_value failed: could not find request trace" };
59
+ throw std::runtime_error{
60
+ " lookup_span_variable_value failed: could not find request trace" };
58
61
}
59
62
return trace->lookup_span_variable_value (key);
60
63
}
@@ -64,21 +67,24 @@ ngx_str_t DatadogContext::lookup_sampling_delegation_response_variable_value(
64
67
auto trace = find_trace (request);
65
68
if (trace == nullptr ) {
66
69
throw std::runtime_error{
67
- " lookup_sampling_delegation_response_variable_value failed: could not find request trace" };
70
+ " lookup_sampling_delegation_response_variable_value failed: could not "
71
+ " find request trace" };
68
72
}
69
73
return trace->lookup_sampling_delegation_response_variable_value ();
70
74
}
71
75
72
76
RequestTracing *DatadogContext::find_trace (ngx_http_request_t *request) {
73
- const auto found = std::find_if (traces_.begin (), traces_.end (),
74
- [=](const auto &trace) { return trace.request () == request; });
77
+ const auto found = std::find_if (
78
+ traces_.begin (), traces_.end (),
79
+ [=](const auto &trace) { return trace.request () == request; });
75
80
if (found != traces_.end ()) {
76
81
return &*found;
77
82
}
78
83
return nullptr ;
79
84
}
80
85
81
- const RequestTracing *DatadogContext::find_trace (ngx_http_request_t *request) const {
86
+ const RequestTracing *DatadogContext::find_trace (
87
+ ngx_http_request_t *request) const {
82
88
return const_cast <DatadogContext *>(this )->find_trace (request);
83
89
}
84
90
@@ -87,7 +93,8 @@ static void cleanup_datadog_context(void *data) noexcept {
87
93
}
88
94
89
95
static ngx_pool_cleanup_t *find_datadog_cleanup (ngx_http_request_t *request) {
90
- for (auto cleanup = request->pool ->cleanup ; cleanup; cleanup = cleanup->next ) {
96
+ for (auto cleanup = request->pool ->cleanup ; cleanup;
97
+ cleanup = cleanup->next ) {
91
98
if (cleanup->handler == cleanup_datadog_context) {
92
99
return cleanup;
93
100
}
@@ -96,8 +103,8 @@ static ngx_pool_cleanup_t *find_datadog_cleanup(ngx_http_request_t *request) {
96
103
}
97
104
98
105
DatadogContext *get_datadog_context (ngx_http_request_t *request) noexcept {
99
- auto context =
100
- static_cast <DatadogContext *>( ngx_http_get_module_ctx (request, ngx_http_datadog_module));
106
+ auto context = static_cast <DatadogContext *>(
107
+ ngx_http_get_module_ctx (request, ngx_http_datadog_module));
101
108
if (context != nullptr || !request->internal ) {
102
109
return context;
103
110
}
@@ -114,7 +121,8 @@ DatadogContext *get_datadog_context(ngx_http_request_t *request) noexcept {
114
121
// If we found a context, attach with ngx_http_set_ctx so that we don't have
115
122
// to loop through the cleanup handlers again.
116
123
if (context != nullptr ) {
117
- ngx_http_set_ctx (request, static_cast <void *>(context), ngx_http_datadog_module);
124
+ ngx_http_set_ctx (request, static_cast <void *>(context),
125
+ ngx_http_datadog_module);
118
126
}
119
127
120
128
return context;
@@ -138,7 +146,8 @@ void set_datadog_context(ngx_http_request_t *request, DatadogContext *context) {
138
146
}
139
147
cleanup->data = static_cast <void *>(context);
140
148
cleanup->handler = cleanup_datadog_context;
141
- ngx_http_set_ctx (request, static_cast <void *>(context), ngx_http_datadog_module);
149
+ ngx_http_set_ctx (request, static_cast <void *>(context),
150
+ ngx_http_datadog_module);
142
151
}
143
152
144
153
// Supports early destruction of the DatadogContext (in case of an
@@ -147,7 +156,8 @@ void destroy_datadog_context(ngx_http_request_t *request) noexcept {
147
156
auto cleanup = find_datadog_cleanup (request);
148
157
if (cleanup == nullptr ) {
149
158
ngx_log_error (NGX_LOG_ERR, request->connection ->log , 0 ,
150
- " Unable to find Datadog cleanup handler for request %p" , request);
159
+ " Unable to find Datadog cleanup handler for request %p" ,
160
+ request);
151
161
return ;
152
162
}
153
163
delete static_cast <DatadogContext *>(cleanup->data );
0 commit comments