Hi Team,
I have added the Javascript for Datadog trace on APIGEE EDGE, While running the JS am getting the below error.
{
"fault": {
"faultstring": "Execution of JS-Trace-Datadog failed with error: Javascript runtime error: \"null\"",
"detail": {
"errorcode": "steps.javascript.ScriptExecutionFailed"
}
}
}
// Set the Datadog API URL here.
// Note: If you are in the Datadog EU site (app.datadoghq.eu), the HTTP log endpoint is http-intake.logs.datadoghq.eu.
// Debug
// print(dd_api_url);
// print('Name of the flow: ' + context.flow);
// calculate response times for client, target and total
var request_start_time = context.getVariable('client.received.start.timestamp');
var request_end_time = context.getVariable('client.received.end.timestamp');
var system_timestamp = context.getVariable('system.timestamp');
var target_start_time = context.getVariable('target.sent.start.timestamp');
var target_end_time = context.getVariable('target.received.end.timestamp');
var total_request_time = system_timestamp - request_start_time;
var total_target_time = target_end_time - target_start_time;
var total_client_time = total_request_time - total_target_time;
var timestamp = crypto.dateFormat('YYYY-MM-dd HH:mm:ss.SSS');
var organization = context.getVariable("organization.name");
var networkClientIP = context.getVariable("client.ip");
var httpPort = context.getVariable("client.port");
var environment = context.getVariable("environment.name");
var apiProduct = context.getVariable("apiproduct.name");
var apigeeProxyName = context.getVariable("apiproxy.name");
var apigeeProxyRevision = context.getVariable("apiproxy.revision");
var appName = context.getVariable("developer.app.name");
var httpMethod = context.getVariable("request.verb");
var httpUrl = '' + context.getVariable("client.scheme") + '://' + context.getVariable("request.header.host") + context.getVariable("request.uri");
var httpStatusCode = context.getVariable("message.status.code");
var statusResponse = context.getVariable("message.reason.phrase");
var clientLatency = total_client_time;
var targetLatency = total_target_time;
var totalLatency = total_request_time;
var userAgent = context.getVariable('request.header.User-Agent');
var messageContent = context.getVariable('message.content');
// Datadog log attributes
var logObject = {
"timestamp": timestamp,
"organization": organization,
"network.client.ip": networkClientIP,
"env": environment,
"apiProduct": apiProduct,
"apigee_proxy.name": apigeeProxyName,
"apigee_proxy.revision": apigeeProxyRevision,
"service": appName,
"http.method": httpMethod,
"http.url": httpUrl,
"http.status_code": httpStatusCode,
"http.port": httpPort,
"status": statusResponse,
"clientLatency": clientLatency,
"targetLatency": targetLatency,
"totalLatency": totalLatency,
"http.client.start_time_ms": request_start_time,
"http.client.end_time_ms": request_end_time,
"http.useragent": userAgent,
"message": messageContent,
};
var headers = {
'Content-Type': 'application/json'
};
// Debug
// print('LOGGING OBJECT' + JSON.stringify(logObject));
var myLoggingRequest = new Request(dd_api_url, "POST", headers, JSON.stringify(logObject));
// Send logs to Datadog
httpClient.send(myLoggingRequest);
Can you please edit the name of your topic to something more meaningful, maybe "Apigee and DataDog integration via JavaScript error"?
// Debug
print('LOGGING OBJECT' + JSON.stringify(logObject));
//var myLoggingRequest = new Request(dd_api_url, "POST", headers, JSON.stringify(logObject));
// Send logs to Datadog
//httpClient.send(myLoggingRequest);
var myLoggingRequest = new Request(dd_api_url, "POST", headers, JSON.stringify(logObject));
// Define the callback function and process the response from the DataDog API request
function onComplete(response, error) {
// Check if the HTTP request was successful
if (response) {
print("Return code: ", response.status.code);
print("Return message: ", response.status.message);
print("Return content: ", response.content);
} else {
context.setVariable('example.error', 'Woops: ' + error);
print("Return code: ", error.status.code);
print("Return message: ", error.status.message);
print("Return content: ", error.content);
}
}
// Send logs to Datadog
httpClient.send(myLoggingRequest, onComplete);
Hope this helps! Or at least gives you some better insight of what's going on. Good luck!
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |