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

Fix: Web Socket Invocation Error with Tracing Enabled #11936

Merged
merged 1 commit into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,27 @@ public boolean handleRequestInFlow(MessageContext messageContext) {
((Axis2MessageContext) messageContext).getAxis2MessageContext();
Map headersMap =
(Map) axis2MessageContext.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
if (headersMap != null) {
Context spanContext = TelemetryUtil.extract(headersMap);

Context spanContext = TelemetryUtil.extract(headersMap);

TelemetrySpan responseLatencySpan = TelemetryUtil.startSpan(APIMgtGatewayConstants.RESPONSE_LATENCY,
spanContext, telemetryTracer);
GatewayUtils.setRequestRelatedTags(responseLatencySpan, messageContext);
messageContext.setProperty(APIMgtGatewayConstants.RESPONSE_LATENCY, responseLatencySpan);
TelemetrySpan responseLatencySpan = TelemetryUtil.startSpan(APIMgtGatewayConstants.RESPONSE_LATENCY,
spanContext, telemetryTracer);
GatewayUtils.setRequestRelatedTags(responseLatencySpan, messageContext);
messageContext.setProperty(APIMgtGatewayConstants.RESPONSE_LATENCY, responseLatencySpan);
}
} else if (Util.tracingEnabled()) {
org.apache.axis2.context.MessageContext axis2MessageContext =
((Axis2MessageContext) messageContext).getAxis2MessageContext();
Map headersMap =
(Map) axis2MessageContext.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
TracingSpan spanContext = Util.extract(tracer, headersMap);
TracingSpan responseLatencySpan =
Util.startSpan(APIMgtGatewayConstants.RESPONSE_LATENCY, spanContext, tracer);
Util.setTag(responseLatencySpan, APIMgtGatewayConstants.SPAN_KIND, APIMgtGatewayConstants.SERVER);
GatewayUtils.setRequestRelatedTags(responseLatencySpan, messageContext);
messageContext.setProperty(APIMgtGatewayConstants.RESPONSE_LATENCY, responseLatencySpan);
if (headersMap != null) {
TracingSpan spanContext = Util.extract(tracer, headersMap);
TracingSpan responseLatencySpan = Util.startSpan(APIMgtGatewayConstants.RESPONSE_LATENCY, spanContext,
tracer);
Util.setTag(responseLatencySpan, APIMgtGatewayConstants.SPAN_KIND, APIMgtGatewayConstants.SERVER);
GatewayUtils.setRequestRelatedTags(responseLatencySpan, messageContext);
messageContext.setProperty(APIMgtGatewayConstants.RESPONSE_LATENCY, responseLatencySpan);
}
}
return true;
}
Expand Down Expand Up @@ -108,13 +111,17 @@ public boolean handleResponseInFlow(MessageContext messageContext) {
if (TelemetryUtil.telemetryEnabled() && messageContext.getProperty(APIMgtGatewayConstants.BACKEND_LATENCY_SPAN) != null) {
TelemetrySpan backendLatencySpan =
(TelemetrySpan) messageContext.getProperty(APIMgtGatewayConstants.BACKEND_LATENCY_SPAN);
GatewayUtils.setEndpointRelatedInformation(backendLatencySpan, messageContext);
TelemetryUtil.finishSpan(backendLatencySpan);
if (backendLatencySpan != null) {
GatewayUtils.setEndpointRelatedInformation(backendLatencySpan, messageContext);
TelemetryUtil.finishSpan(backendLatencySpan);
}
} else if (Util.tracingEnabled() && messageContext.getProperty(APIMgtGatewayConstants.BACKEND_LATENCY_SPAN) != null) {
TracingSpan backendLatencySpan =
(TracingSpan) messageContext.getProperty(APIMgtGatewayConstants.BACKEND_LATENCY_SPAN);
GatewayUtils.setEndpointRelatedInformation(backendLatencySpan, messageContext);
Util.finishSpan(backendLatencySpan);
if (backendLatencySpan != null) {
GatewayUtils.setEndpointRelatedInformation(backendLatencySpan, messageContext);
Util.finishSpan(backendLatencySpan);
}
}
return true;
}
Expand All @@ -129,14 +136,16 @@ public boolean handleResponseOutFlow(MessageContext messageContext) {
}
TelemetrySpan responseLatencySpan =
(TelemetrySpan) messageContext.getProperty(APIMgtGatewayConstants.RESPONSE_LATENCY);
GatewayUtils.setAPIRelatedTags(responseLatencySpan, messageContext);
API api = GatewayUtils.getAPI(messageContext);
if (api != null) {
TelemetryUtil.updateOperation(responseLatencySpan,
api.getApiName().concat("--").concat(api.getApiVersion()).concat("--")
.concat(GatewayUtils.getTenantDomain()));
if (responseLatencySpan != null) {
GatewayUtils.setAPIRelatedTags(responseLatencySpan, messageContext);
API api = GatewayUtils.getAPI(messageContext);
if (api != null) {
TelemetryUtil.updateOperation(responseLatencySpan,
api.getApiName().concat("--").concat(api.getApiVersion()).concat("--")
.concat(GatewayUtils.getTenantDomain()));
}
TelemetryUtil.finishSpan(responseLatencySpan);
}
TelemetryUtil.finishSpan(responseLatencySpan);
} else if (Util.tracingEnabled()) {
Object resourceSpanObject = messageContext.getProperty(APIMgtGatewayConstants.RESOURCE_SPAN);
if (resourceSpanObject != null) {
Expand All @@ -145,13 +154,18 @@ public boolean handleResponseOutFlow(MessageContext messageContext) {
}
TracingSpan responseLatencySpan =
(TracingSpan) messageContext.getProperty(APIMgtGatewayConstants.RESPONSE_LATENCY);
GatewayUtils.setAPIRelatedTags(responseLatencySpan, messageContext);
API api = GatewayUtils.getAPI(messageContext);
if (api != null) {
Util.updateOperation(responseLatencySpan, api.getApiName().concat("--").concat(api
.getApiVersion()).concat("--").concat(GatewayUtils.getTenantDomain()));
if (responseLatencySpan != null) {
GatewayUtils.setAPIRelatedTags(responseLatencySpan, messageContext);
API api = GatewayUtils.getAPI(messageContext);
if (api != null) {
Util.updateOperation(responseLatencySpan,
api.getApiName().concat("--").concat(api.getApiVersion()).concat("--")
.concat(GatewayUtils.getTenantDomain()));
}
if (responseLatencySpan != null) {
Util.finishSpan(responseLatencySpan);
}
}
Util.finishSpan(responseLatencySpan);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ private static void setTracingId(TracingSpan tracingSpan, MessageContext axis2Me
Map headersMap =
(Map) axis2MessageContext.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);

if (headersMap.containsKey(APIConstants.ACTIVITY_ID)) {
if (headersMap != null && headersMap.containsKey(APIConstants.ACTIVITY_ID)) {
Util.setTag(tracingSpan, APIMgtGatewayConstants.SPAN_ACTIVITY_ID,
(String) headersMap.get(APIConstants.ACTIVITY_ID));
} else {
Expand All @@ -1200,7 +1200,7 @@ private static void setTracingId(TelemetrySpan tracingSpan, MessageContext axis2
Map headersMap =
(Map) axis2MessageContext.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);

if (headersMap.containsKey(APIConstants.ACTIVITY_ID)) {
if (headersMap != null && headersMap.containsKey(APIConstants.ACTIVITY_ID)) {
TelemetryUtil.setTag(tracingSpan, APIMgtGatewayConstants.SPAN_ACTIVITY_ID,
(String) headersMap.get(APIConstants.ACTIVITY_ID));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,19 @@ public void unregisterTenantSubscriptionStore(String tenantDomain) {
}

public SubscriptionDataStore getTenantSubscriptionStore(String tenantDomain) {
SubscriptionDataStore subscriptionDataStore = subscriptionStore.get(tenantDomain);
if (subscriptionDataStore == null) {
synchronized (tenantDomain.concat("getTenantSubscriptionStore").intern()) {
subscriptionDataStore = subscriptionStore.get(tenantDomain);
if (subscriptionDataStore == null) {
subscriptionDataStore = registerTenantSubscriptionStore(tenantDomain);
if (subscriptionStore != null && tenantDomain != null) {
SubscriptionDataStore subscriptionDataStore = subscriptionStore.get(tenantDomain);
if (subscriptionDataStore == null) {
synchronized (tenantDomain.concat("getTenantSubscriptionStore").intern()) {
subscriptionDataStore = subscriptionStore.get(tenantDomain);
if (subscriptionDataStore == null) {
subscriptionDataStore = registerTenantSubscriptionStore(tenantDomain);
}
}
}
return subscriptionDataStore;
}
return subscriptionDataStore;
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Did we check if there are any possible null pointers that can occur as a result of sending null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

}

}