@@ -176,6 +176,20 @@ static ngx_command_t datadog_commands[] = {
176176 0 ,
177177 nullptr ),
178178
179+ { ngx_string (" datadog_resource_name" ),
180+ anywhere | NGX_CONF_TAKE1,
181+ set_datadog_resource_name,
182+ NGX_HTTP_LOC_CONF_OFFSET,
183+ 0 ,
184+ nullptr },
185+
186+ { ngx_string (" datadog_location_resource_name" ),
187+ anywhere | NGX_CONF_TAKE1,
188+ set_datadog_location_resource_name,
189+ NGX_HTTP_LOC_CONF_OFFSET,
190+ 0 ,
191+ nullptr },
192+
179193 DEFINE_COMMAND_WITH_OLD_ALIAS (
180194 " datadog_trust_incoming_span" ,
181195 " opentracing_trust_incoming_span" ,
@@ -295,10 +309,13 @@ static ngx_int_t datadog_module_init(ngx_conf_t *cf) noexcept {
295309 if (tags.empty ()) return NGX_OK;
296310 main_conf->tags = ngx_array_create (cf->pool , tags.size (), sizeof (datadog_tag_t ));
297311 if (!main_conf->tags ) return NGX_ERROR;
298- for (const auto &tag : tags)
312+ for (const auto &tag : tags) {
299313 if (add_datadog_tag (cf, main_conf->tags , to_ngx_str (tag.first ), to_ngx_str (tag.second )) !=
300- NGX_CONF_OK)
314+ NGX_CONF_OK) {
301315 return NGX_ERROR;
316+ }
317+ }
318+
302319 return NGX_OK;
303320}
304321
@@ -398,13 +415,13 @@ static void *create_datadog_loc_conf(ngx_conf_t *conf) noexcept {
398415
399416namespace {
400417
401- // Merge the specified `previous` operation name script into the specified
402- // `current` operation name script in the context of the specified `conf`. If
403- // `current` does not have a value and ` previous` does, then `previous` will be
404- // used. If neither has a value, then a hard-coded default will be used.
405- // Return `NGX_CONF_OK` on success, or another value otherwise.
406- char *merge_operation_name_script (ngx_conf_t *conf, NgxScript &previous, NgxScript ¤t,
407- ot::string_view default_pattern) {
418+ // Merge the specified `previous` script into the specified `current` script in
419+ // the context of the specified `conf`. If `current` does not have a value and
420+ // `previous` does, then `previous` will be used. If neither has a value, then
421+ // the specified `default_pattern` will be used. Return `NGX_CONF_OK` on
422+ // success, or another value otherwise.
423+ char *merge_script (ngx_conf_t *conf, NgxScript &previous, NgxScript ¤t,
424+ ot::string_view default_pattern) {
408425 if (current.is_valid ()) {
409426 return NGX_CONF_OK;
410427 }
@@ -420,28 +437,6 @@ char *merge_operation_name_script(ngx_conf_t *conf, NgxScript &previous, NgxScri
420437 return NGX_CONF_OK;
421438}
422439
423- char *merge_response_info_script (ngx_conf_t *conf, NgxScript &previous, NgxScript ¤t) {
424- // The response info script is the same for each `datadog_loc_conf_t`. The only
425- // reason it's a member of `datadog_loc_conf_t` is so that it is available at
426- // the end of each request, when we might like to inspect e.g. response
427- // headers.
428- if (current.is_valid ()) {
429- return NGX_CONF_OK;
430- }
431-
432- if (!previous.is_valid ()) {
433- // Response header inspection is not currently used by this module, but I'm
434- // leaving the boilerplate for future use.
435- const ngx_int_t rc = previous.compile (conf, ngx_string (" " ));
436- if (rc != NGX_OK) {
437- return (char *)NGX_CONF_ERROR;
438- }
439- }
440-
441- current = previous;
442- return NGX_CONF_OK;
443- }
444-
445440} // namespace
446441
447442// ------------------------------------------------------------------------------
@@ -455,19 +450,26 @@ static char *merge_datadog_loc_conf(ngx_conf_t *cf, void *parent, void *child) n
455450 ngx_conf_merge_value (conf->enable_locations , prev->enable_locations ,
456451 TracingLibrary::trace_locations_by_default ());
457452
453+ if (const auto rc = merge_script (cf, prev->operation_name_script , conf->operation_name_script ,
454+ TracingLibrary::default_request_operation_name_pattern ())) {
455+ return rc;
456+ }
458457 if (const auto rc =
459- merge_operation_name_script (cf, prev->operation_name_script , conf->operation_name_script ,
460- TracingLibrary::default_request_operation_name_pattern ())) {
458+ merge_script (cf, prev->loc_operation_name_script , conf->loc_operation_name_script ,
459+ TracingLibrary::default_location_operation_name_pattern ())) {
461460 return rc;
462461 }
463- if (const auto rc = merge_operation_name_script (
464- cf, prev->loc_operation_name_script , conf->loc_operation_name_script ,
465- TracingLibrary::default_location_operation_name_pattern ())) {
462+ if (const auto rc = merge_script (cf, prev->resource_name_script , conf->resource_name_script ,
463+ TracingLibrary::default_resource_name_pattern ())) {
464+ return rc;
465+ }
466+ if (const auto rc =
467+ merge_script (cf, prev->loc_resource_name_script , conf->loc_resource_name_script ,
468+ TracingLibrary::default_resource_name_pattern ())) {
466469 return rc;
467470 }
468-
469471 if (const auto rc =
470- merge_response_info_script (cf, prev->response_info_script , conf->response_info_script )) {
472+ merge_script (cf, prev->response_info_script , conf->response_info_script , " " )) {
471473 return rc;
472474 }
473475
@@ -510,8 +512,8 @@ static char *merge_datadog_loc_conf(ngx_conf_t *cf, void *parent, void *child) n
510512
511513 *tag = kv.second ;
512514 } else {
513- datadog_tag_t *tag = (datadog_tag_t *)conf->tags ->elts ;
514- tag [index] = kv.second ;
515+ datadog_tag_t *tags = (datadog_tag_t *)conf->tags ->elts ;
516+ tags [index] = kv.second ;
515517 }
516518
517519 index++;
0 commit comments