DataDog / kong-plugin-ddtrace

Datadog APM Plugin for Kong Gateway
Apache License 2.0
15 stars 7 forks source link

[Bug]: `kong.log.warning` Function Call Results in `nil` Error #48

Closed tmizohata-alist closed 2 months ago

tmizohata-alist commented 3 months ago

Kong Version

3.3.1

Plugin Version

0.2.0

On which environment your Kong instance is running?

Kubernetes

Plugin Configuration

config:
  service_name: api-gateway
  agent_endpoint:
  trace_agent_port:
  header_tags:
  static_tags:
  injection_propagation_styles:
  - datadog
  - tracecontext
  extraction_propagation_styles:
  - datadog
  - tracecontext
  initial_samples_per_second: 100
  version:
  max_header_size: 512
  resource_name_rule:
  generate_128bit_trace_ids: true
  environment:
  trace_agent_url: http://ddagent:8126
  initial_sample_rate:
  agent_host:

What happened?

I have recently started using the ddtrace plugin. While the plugin appears to function correctly in terms of features, numerous error messages are generated in the logs.

Error Log:

[kong] handler.lua:360 
[ddtrace] tracing error in DatadogTraceHandler:header_filter: /usr/local/share/lua/5.1/kong/plugins/ddtrace/w3c_propagation.lua:104:
  attempt to call field 'warning' (a nil value) while reading response header from upstream

By looking at the code

if tracestate then
    dd_state, err = parse_datadog_tracestate(tracestate)
    if err then
        kong.log.warning(err)
    end
end

kong.log seems to be nil on some occasions. Is this a bug? Or you think some configurations can fix this?

dmehala commented 2 months ago

Hi @tmizohata-alist

Thank you for reporting this issue and your investigation. My mistake was not carefully reading the kong.log documentation. I should have used kong.log.warn instead of kong.log.warning.

I'll fix it soon. Thanks!

tmizohata-alist commented 2 months ago

I prepare a PR for this (sorry, it's from a different account). If you can take a look and release this, that'd be wonderful. Thanks!

dmehala commented 2 months ago

PR merged. Your fix will be included in the next release, once the number of reported issues related to the new version will stop growing.

Thanks 😉