How can software code get online sampling rules?

0

https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-dotnet-configuration.html

The configuration method for .NET apps only shows how to grab rules from a local JSON file.

But how can an app query and grab sampling rules already defined beforehand in AWS console?

And beyond that, if the online sampling rules are adjusted, do they get dynamically propagated to all existing related app systems?

icelava
已提問 3 年前檢視次數 178 次
5 個答案
0

Hi,

As long as your application has X-Ray SDK instrumented, the SDK will periodically check X-Ray backend to fetch the centralized sampling rule that you defined in X-Ray console.

aws-lu
已回答 2 年前
0

But how do we grab specific sampling rules? We have multiple systems, tiers, environments and they won't be operating with the same sampling rate.

icelava
已回答 2 年前
0

Hello,

If you would like to create a custom solution involving manually retrieving your sampling rules, you can call the GetSamplingRules API: https://docs.aws.amazon.com/xray/latest/api/API_GetSamplingRules.html

This will return all sampling rules you've created on the X-Ray console, and you can select the one that you'd like to apply.

AWS
已回答 2 年前
0

For ASP.NET Core app, the Startup.Configure() method registers the app's main segment name.

app.UseXRay("APPSERVICENAME", this.Configuration);

A sampling rule with Service name equaling that app name must be created for it to be fetched and applied automatically.

HOWEVER

My sample infrastructure is multi-tier; there is another back-end web app that receives HTTP requests from the front-end web app. The back-end service has its own sampling rule. But on inspecting the traces, it appears only the front-end sampling rule was applied. Is it because the back-end is considered a sub-segment and thus slaved to the front-end's sampling rule?

{
"Id": "1-61adbe98-2dbb90b3efdd86e20c536db3",
"Duration": 0.544,
"LimitExceeded": false,
"Segments": [
{
"Id": "9ec8aad6f0dfe2d6",
"Document": {
"id": "9ec8aad6f0dfe2d6",
"name": "XRayBackApi-exp",
"start_time": 1638776472.237228,
"trace_id": "1-61adbe98-2dbb90b3efdd86e20c536db3",
"end_time": 1638776472.752401,
"parent_id": "2ac704e5eba6c989",
"http": {
"request": {
"url": "http://localhost:8081/api/Tier",
"method": "GET",
"client_ip": "::1"
},
"response": {
"status": 200
}
},
"aws": {
"xray": {
"sdk_version": "2.10.1",
"sdk": "X-Ray for .NET Core"
}
},
"annotations": {
"System": "XRay-exp"
},
"service": {
"runtime": ".NET Core Framework",
"runtime_version": "3.1.21"
}
}
},
{
"Id": "a70b7cc33c3e6d9a",
"Document": {
"id": "a70b7cc33c3e6d9a",
"name": "XRayFrontWeb-exp",
"start_time": 1638776472.217652,
"trace_id": "1-61adbe98-2dbb90b3efdd86e20c536db3",
"end_time": 1638776472.761628,
"http": {
"request": {
"url": "http://localhost:8080/Home/MultiTierResponsiveness",
"method": "GET",
"user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36 Edg/95.0.1020.53",
"client_ip": "::1"
},
"response": {
"status": 200
}
},
"aws": {
"xray": {
"sampling_rule_name": "XRayFrontWeb-exp",
"sdk_version": "2.10.1",
"sdk": "X-Ray for .NET Core"
}
},
"annotations": {
"System": "XRay-exp"
},
"service": {
"runtime": ".NET Core Framework",
"runtime_version": "3.1.21"
},
"subsegments": [
{
"id": "2ac704e5eba6c989",
"name": "localhost",
"start_time": 1638776472.219333,
"end_time": 1638776472.752914,
"http": {
"request": {
"url": "http://localhost:8081/api/Tier",
"method": "GET"
},
"response": {
"status": 200
}
},
"namespace": "remote"
}
]
}
}
]
}

icelava
已回答 2 年前
0

Tested a separate PHP-Laravel front-end tier which does not have sampling rule and omitted the Sampled=1 parameter from the X-Amzn-Trace-Id HTTP header for back-end web requests. With this setup, the back-end can apply its own sampling rule.

{
"Id": "1-61adc749-e0aa74be2a8ed62ace626b04",
"Duration": 1.5,
"LimitExceeded": false,
"Segments": [
{
"Id": "561ad6c8c7cb840f",
"Document": {
"id": "561ad6c8c7cb840f",
"name": "XRayLaravel-exp",
"start_time": 1638778697.660007,
"trace_id": "1-61adc749-e0aa74be2a8ed62ace626b04",
"end_time": 1638778699.089339,
"http": {
"request": {
"url": "http://localhost:9091/traceapi",
"method": "GET",
"client_ip": "127.0.0.1"
},
"response": {
"status": 200
}
},
"annotations": {
"System": "XRay-exp",
"Framework": "Laravel 8.68.1"
},
"subsegments": [
{
"id": "54675e8f2c067792",
"name": "laravel boot",
"start_time": 1638778697.589603,
"end_time": 1638778697.677686,
"subsegments": [
{
"id": "e7c3d03023f9d693",
"name": "route matching",
"start_time": 1638778697.677683,
"end_time": 1638778697.681337,
"annotations": {
"route": "AppHttpControllersXRayController@trace"
}
}
]
},
{
"id": "91a295beee84cb18",
"name": "request handled",
"start_time": 1638778697.681333,
"end_time": 1638778699.089067,
"metadata": {
"info": {
"controller": "AppHttpControllersXRayController@trace"
}
},
"subsegments": [
{
"id": "4dd5a4d45a805237",
"name": "XRayController",
"start_time": 1638778697.688244,
"end_time": 1638778699.085528
},
{
"id": "eefd7b032b90997b",
"name": "View traceapi",
"start_time": 1638778699.086454,
"end_time": 1638778699.087839
}
]
}
]
}
},
{
"Id": "6b5b0eba10878dc1",
"Document": {
"id": "6b5b0eba10878dc1",
"name": "XRayBackApi-exp",
"start_time": 1638778697.717974,
"trace_id": "1-61adc749-e0aa74be2a8ed62ace626b04",
"end_time": 1638778699.083292,
"parent_id": "4dd5a4d45a805237",
"http": {
"request": {
"url": "http://localhost:8081/api/Tier",
"method": "GET",
"user_agent": "GuzzleHttp/7",
"client_ip": "::1"
},
"response": {
"status": 200
}
},
"aws": {
"xray": {
"sampling_rule_name": "XRayBackApi-exp",
"sdk_version": "2.10.1",
"sdk": "X-Ray for .NET Core"
}
},
"annotations": {
"System": "XRay-exp"
},
"service": {
"runtime": ".NET Core Framework",
"runtime_version": "3.1.21"
}
}
}
]
}

So it does appear that back-tier sub-segments are slaved to the parent segment sampling rule.

icelava
已回答 2 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南