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

Could not get binary context for sub requests #133

Open
ichaozai opened this issue Jul 2, 2020 · 1 comment
Open

Could not get binary context for sub requests #133

ichaozai opened this issue Jul 2, 2020 · 1 comment

Comments

@ichaozai
Copy link

ichaozai commented Jul 2, 2020

Get failed to expand opentracing_context_ for request 000055D4589C9190: get_binary_context failed: could not find request trace when invoking subrequest by ngx lua.

$ curl 127.0.0.1:8080
2020/07/02 10:22:11 [error] 308#308: *22 failed to expand opentracing_context_ for request 000055D4589C9190: get_binary_context failed: could not find request trace, client: 127.0.0.1, server: , request: "GET / HTTP/1.1", subrequest: "/sub", host: "127.0.0.1:8080"
terminate called without an active exception
2020/07/02 10:22:11 [alert] 154#154: worker process 308 exited on signal 6
curl: (52) Empty reply from server

How to trace sub requests?

nginx.conf:

load_module modules/ngx_http_opentracing_module.so;
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    opentracing on;
    opentracing_load_tracer /usr/local/lib/libjaegertracing_plugin.so jaeger-config.json;
    opentracing_propagate_context;

    server {
        listen 8080;
        location / {
            default_type text/html;
            content_by_lua '
                local bridge_tracer = require("opentracing_bridge_tracer")
                local tracer = bridge_tracer.new_from_global()
                local parent_context = tracer:binary_extract(ngx.var.opentracing_binary_context)
                local span = tracer:start_span("lua-hello", {["references"] = {{"child_of", parent_context}}})
                local res = ngx.location.capture("/sub")
                ngx.say(res.body)
                span:finish()
            ';
        }

        location /sub {
            default_type text/html;
            content_by_lua '
                local bridge_tracer = require("opentracing_bridge_tracer")
                local tracer = bridge_tracer.new_from_global()
                local parent_context = tracer:binary_extract(ngx.var.opentracing_binary_context)
                local span = tracer:start_span("sub-lua-hello", {["references"] = {{"child_of", parent_context}}})
                ngx.say("<p>hello, world</p>")
                span:finish()
            ';
        }
    }
}

jaeger-config.json:

{
  "service_name": "nginx",
  "diabled": false,
  "reporter": {
    "logSpans": true,
    "localAgentHostPort": "127.0.0.1:6831"
  },
  "sampler": {
    "type": "const",
    "param": "1"
  }
}
@ichaozai
Copy link
Author

ichaozai commented Jul 6, 2020

After debugging from the source code, I need to set log_subrequest on; to enable sub request tracing.

But I got a new problem, the sub request's span is not a child of the caller request.
Here is the nginx.conf:

load_module modules/ngx_http_opentracing_module.so;

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    opentracing on;
    opentracing_load_tracer /usr/local/lib/libjaegertracing_plugin.so jaeger-config.json;
    opentracing_propagate_context;
    log_subrequest on;

    server {
        listen 8080;
        location / {
            default_type text/html;
            content_by_lua '
                local res = ngx.location.capture("/sub")
                ngx.say(res.body)
            ';
        }

        location /sub {
            default_type text/html;
            content_by_lua '
                ngx.say("<p>hello, world</p>")
            ';
        }
    }
}

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

No branches or pull requests

1 participant