Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of support for custom resource attributes #54

Closed
wants to merge 2 commits into from

Conversation

puhre
Copy link

@puhre puhre commented May 27, 2024

Proposed changes

This pull requests adds support for optional resources attributes. The resource attributes are configured, similar to what was suggested in the Issue #32, using a block configuration, e.g.

	otel_resource_attr {
		service.namespace 	test;
	}

fix Custom Resource Attributes

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the CONTRIBUTING document
  • If applicable, I have added tests that prove my fix is effective or that my feature works
  • If applicable, I have checked that any relevant tests pass after adding my changes

@puhre puhre force-pushed the custom-resource-attributes branch from 90eba3d to c39f334 Compare May 28, 2024 12:35
@brettmc
Copy link

brettmc commented Jul 17, 2024

This is just what I need. Any progress on having this reviewed?

Copy link
Contributor

@p-pautov p-pautov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for PR and sorry for late response. See some issues below.

@@ -112,7 +117,7 @@ class BatchExporter {
};

BatchExporter(StrView target,
size_t batchSize, size_t batchCount, StrView serviceName) :
size_t batchSize, size_t batchCount, StrView serviceName, ngx_array_t customResourceAttrs) :
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For most part, we try to avoid "ngx_*" types in this file and use C++ types. Looks like, for attributes we can use const std::map<StrView, StrView>& attrs.

@@ -124,6 +129,15 @@ class BatchExporter {
attr->set_key("service.name");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have explicit otel_service_name directive, it shouldn't be overridden by resource attributes block, which is currently the case. Although, it should be possible to define "service.name" via block, if there is no explicit otel_service_name. Makes sense to remove serviceName argument and keep that logic outside.

auto attrs = (ResourceAttr*)customResourceAttrs.elts;
for (ngx_uint_t i = 0; i < customResourceAttrs.nelts; i++) {
attr = resourceSpans->mutable_resource()->add_attributes();
StrView value = StrView((char*)attrs[i].value.value.data, attrs[i].value.value.len);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not how complex values work. We can't really use complex value here, as those require client request to be evaluated.

@@ -67,6 +69,12 @@ ngx_command_t gCommands[] = {
ngx_conf_set_str_slot,
NGX_HTTP_MAIN_CONF_OFFSET,
offsetof(MainConf, serviceName) },

{ ngx_string("otel_resource_attr"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was to call the block "otel_resource" and, perhaps, add some other resource related options to it later on (or even support multiple resources).

"otel_resource_attr" name makes more sense for single attribute directive, like otel_resource_attr name value;. It's a reasonable approach, but then it shouldn't be a block.


if (mcf->endpoint.len == 0) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
"\"otel_exporter\" requires \"endpoint\"");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this related?


attr->name = args[0];

ngx_http_compile_complex_value_t ccv = { cf, &args[1], &attr->value };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if there is only one arg?

char* addResourceAttr(ngx_conf_t* cf, ngx_command_t* cmd, void* conf) {
auto mcf = (MainConf*)conf;

if (mcf->resourceAttrs.elts == NULL && ngx_array_init(&mcf->resourceAttrs,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a similar code below. Is that intentional?

@@ -455,6 +463,7 @@ void addCustomAttrs(BatchExporter::Span& span, ngx_http_request_t* r)
}
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accidental edit?

@@ -47,6 +47,10 @@ http {
batch_count 1;
}

otel_resource_attr {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given, these attributes are not HTTP version related, I don't think we need to add them into h2/h3 tests.

@@ -46,6 +46,10 @@ http {
batch_count 2;
}

otel_resource_attr {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note indent.

@tatchi
Copy link

tatchi commented Oct 2, 2024

Hey, what's the status of this PR? Although I don't have much experience in C, please let me know if I can do anything to help move this PR forward

@puhre
Copy link
Author

puhre commented Oct 2, 2024

Hey, what's the status of this PR? Although I don't have much experience in C, please let me know if I can do anything to help move this PR forward

I have moved to another solution which does not involve nginx so this is not a priority for me anymore. If you want to go ahead and continue this PR by resolving the comments you are more than welcome. I will probably not get around to it for a while.

@p-pautov
Copy link
Contributor

The functionality will be added via #74.

@p-pautov p-pautov closed this Nov 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support arbitrary resource attributes
4 participants