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

Setting client span attributes #187

Open
wants to merge 13 commits into
base: webserver-dev
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,14 @@ struct InteractionPayload
std::string phaseName;
bool resolveBackends;

std::string target;
std::string scheme;
std::string host;

InteractionPayload() {}

InteractionPayload(std::string module, std::string phase, bool b) : moduleName(module), phaseName(phase), resolveBackends(b)
InteractionPayload(std::string module, std::string phase, bool b, std::string aTarget, std::string aScheme, std::string aHost)
: moduleName(module), phaseName(phase), resolveBackends(b), target(aTarget), scheme(aScheme), host(aHost)
{}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void initDependency();
void populatePayload(request_payload* req_payload, void* payload, int count);
APPD_SDK_STATUS_CODE opentelemetry_core_init(APPD_SDK_ENV_RECORD* env, unsigned numberOfRecords, struct cNode *rootCN);
APPD_SDK_STATUS_CODE startRequest(const char* wscontext, request_payload* req_payload, APPD_SDK_HANDLE_REQ* reqHandle, int count);
APPD_SDK_STATUS_CODE startModuleInteraction(const char* req_handle_key, const char* module_name, const char* stage, bool resolveBackends, APPD_SDK_ENV_RECORD* propagationHeaders, int* ix);
APPD_SDK_STATUS_CODE startModuleInteraction(const char* req_handle_key, const char* module_name, const char* stage, bool resolveBackends, APPD_SDK_ENV_RECORD* propagationHeaders, int* ix, const char* target, const char* scheme, const char* host);
APPD_SDK_STATUS_CODE stopModuleInteraction(const char* req_handle_key, const char* backendName, const char* backendType, unsigned int err_code, const char* msg);
APPD_SDK_STATUS_CODE endRequest(APPD_SDK_HANDLE_REQ req_handle_key, const char* errMsg);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ APPD_SDK_STATUS_CODE ApacheHooks::appd_startInteraction(
}

std::unique_ptr<appd::core::InteractionPayload> payload(new
appd::core::InteractionPayload(module, stage, resolveBackends));
appd::core::InteractionPayload(module, stage, resolveBackends, r->server->server_hostname, ap_run_http_scheme(r), r->hostname));

// Create propagationHeaders to be populated in startInteraction.
std::unordered_map<std::string, std::string> propagationHeaders;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ APPD_SDK_STATUS_CODE RequestProcessingEngine::startInteraction(
std::string spanName = payload->moduleName + "_" + payload->phaseName;
keyValueMap["interactionType"] = "EXIT_CALL";
auto interactionSpan = m_sdkWrapper->CreateSpan(spanName, SpanKind::CLIENT, keyValueMap);
interactionSpan->AddAttribute("http.target", payload->target);
interactionSpan->AddAttribute("http.scheme", payload->scheme);
interactionSpan->AddAttribute("http.host", payload->host);
LOG4CXX_TRACE(mLogger, "Client Span started with SpanName: " << spanName
<< " Span Id: " << interactionSpan.get());
m_sdkWrapper->PopulatePropagationHeaders(propagationHeaders);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,13 @@ APPD_SDK_STATUS_CODE endRequest(APPD_SDK_HANDLE_REQ req_handle_key, const char*
return res;
}

APPD_SDK_STATUS_CODE startModuleInteraction(const char* req_handle_key, const char* module_name, const char* stage, bool resolveBackends, APPD_SDK_ENV_RECORD* propagationHeaders, int *ix)
APPD_SDK_STATUS_CODE startModuleInteraction(const char* req_handle_key, const char* module_name, const char* stage, bool resolveBackends, APPD_SDK_ENV_RECORD* propagationHeaders, int *ix, const char* target, const char* scheme, const char* host)
{
APPD_SDK_STATUS_CODE res = APPD_SUCCESS;
std::unordered_map<std::string, std::string> pHeaders;
std::string module(module_name);
std::string m_stage(stage);

std::unique_ptr<appd::core::InteractionPayload> payload(new appd::core::InteractionPayload(module, m_stage, resolveBackends));
std::unique_ptr<appd::core::InteractionPayload> payload(new appd::core::InteractionPayload(module, m_stage, resolveBackends, target, scheme, host));
res = wsAgent.startInteraction((APPD_SDK_HANDLE_REQ)req_handle_key, payload.get(), pHeaders);

if (APPD_ISSUCCESS(res))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,8 @@ static APPD_SDK_STATUS_CODE otel_startInteraction(ngx_http_request_t* r, const c
}
ngx_writeTrace(r->connection->log, __func__, "Starting a new module interaction for: %s", module_name);
int ix = 0;
res = startModuleInteraction(ctx->otel_req_handle_key, module_name, "", resolveBackends, propagationHeaders, &ix);
// Todo : In the below line $scheme is Ngnix variable, need to findn correct way to retrieve this
res = startModuleInteraction(ctx->otel_req_handle_key, module_name, "", resolveBackends, propagationHeaders, &ix, (const char*)(r->unparsed_uri.data), "$scheme", (const char*)(r->headers_in.host->value.data));

if (APPD_ISSUCCESS(res))
{
Expand Down