1 year ago
#236726
Golide
Why are my services not registering with Jaeger?
I have deployed two services in kubernetes (bare-metal k0s. To do some tracing on Jaeger Service A makes a call to Service B for a JWT authentication token - this works perfectly when I test in Visual Studio (Service A is able to retrieve token from Service B).
However when I execute the call in Postman now that I have deployed to k0S , I cannot see neither the services or any traces Jaeger UI :
Using guide from here I have configured the services as below :
Service A (Startup.cs)
public class Startup
{
private readonly IWebHostEnvironment _environment;
public Startup(IConfiguration configuration, IWebHostEnvironment environment)
{
Configuration = configuration;
_environment = environment;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddDbContext<ModelContext>(o => o.UseOracle(Configuration.GetConnectionString("OracleConn")));
services.AddCors(c =>
{
c.AddPolicy("AllowOrigin", options => options.AllowAnyOrigin());
});
services.AddTransient<IAsyncAccountService<SttmCustAccount>, AccountService>();
services.AddTransient<IAsyncLookupResponse, LookupService>();
services.AddOpenTracing();
services.AddSingleton<ITracer>(cli =>
{
var serviceName = cli.GetRequiredService<IWebHostEnvironment>().ApplicationName;
Environment.SetEnvironmentVariable("JAEGER_SERVICE_NAME", serviceName);
if (_environment.IsDevelopment())
{
Environment.SetEnvironmentVariable("JAEGER_AGENT_HOST", "localhost");
Environment.SetEnvironmentVariable("JAEGER_AGENT_PORT", "6831");
Environment.SetEnvironmentVariable("JAEGER_SAMPLER_TYPE", "const");
}
ILoggerFactory loggerFactory = cli.GetRequiredService<ILoggerFactory>();
ISampler sampler = new ConstSampler(sample: true);
ITracer tracer = new Tracer.Builder(serviceName)
.WithLoggerFactory(loggerFactory)
.WithSampler(sampler)
.Build();
GlobalTracer.Register(tracer);
return tracer;
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
}
Service B has the exact same configuration.
Jaeger operator is set up using NodePort with config as in this file :
[file][https://drive.google.com/file/d/1nAjQ2jHrLSZLWoV9vGb3l4b0M1_yTMTw/view?usp=sharing]
I have to tried to expose the operator as Traefik Ingress but failed and had to change to NodePort (Can this affect registering of services , if at all ?) :
This is the call in Service A that retrieves token from Service B :
[HttpGet]
public async Task<IActionResult> GetAccountAsync([FromQuery] AccountLookupRequest request)
{
string authenticationResponse = await GetTokenAsync();
if (authenticationResponse != null)
{
_logger.LogInformation("Called AccountLookup API");
List<AccountLookupResponse> res = new List<AccountLookupResponse>();
var tranRef = String.Format("{1}{2}{0}", Helpers.aa, Helpers.bb, DateTime.Now.ToString("yyMMddHHmmss"));
...
}
}
static async Task<string> GetTokenAsync()
{
var payload = "{\"Username\": \"golide\",\"Password\": \"It@XXXXX\"}";
Uri uri = new Uri("http://10.XXX.XXX.XXX:31306/users/authenticate");
HttpContent c = new StringContent(payload, Encoding.UTF8, "application/json");
AuthenticationResponse responseEntity = new AuthenticationResponse();
var response = string.Empty;
using (var client = new HttpClient())
{
HttpResponseMessage result = await client.PostAsync(uri, c);
if (result.IsSuccessStatusCode)
{
response = result.StatusCode.ToString();
// responseEntity = JsonConvert.DeserializeObject<AuthenticationResponse>(response);
}
}
return response;
}
In Postman context the call to http://10.170.XXX.XXX:30488/account?field4=3025202645050&field7=GENERIC01&field10=ABC076 will implicitly invoke the AuthenticationAPI at http://10.170.xxx.xxx:31306/users/authenticate
UPDATE Container logs show that trace-id and span-id are being generated :
[02:54:03 INF] Executed action method
FlexToEcocash.Controllers.AccountController.GetAccountAsync (FlexToEcocash), returned result Microsoft.AspNetCore.Mvc.OkObjectResult in 416.2876ms.
[02:54:03 WRN] Event-Exception: Microsoft.AspNetCore.Mvc.BeforeActionResult
System.NullReferenceException: Object reference not set to an instance of an object.
at System.Object.GetType()
at OpenTracing.Contrib.NetCore.AspNetCore.MvcEventProcessor.ProcessEvent(String eventName, Object arg)
at OpenTracing.Contrib.NetCore.AspNetCore.AspNetCoreDiagnostics.OnNext(String eventName, Object untypedArg)
at OpenTracing.Contrib.NetCore.Internal.DiagnosticListenerObserver.System.IObserver<System.Collections.Generic.KeyValuePair<System.String,System.Object>>.OnNext(KeyValuePair`2 value)
[02:54:03 INF] Executing ObjectResult, writing value of type 'FlexToEcocash.Models.ResponseModels.AccountLookupResponse'.
[02:54:03 INF] Executed action FlexToEcocash.Controllers.AccountController.GetAccountAsync (FlexToEcocash) in 421.8383ms
[02:54:03 WRN] Span has already been finished; will not be reported again. Operation: HTTP GET Trace Id: c976e25bf21bfae5 Span Id: c976e25bf21bfae5
[02:54:03 INF] Executed endpoint 'FlexToEcocash.Controllers.AccountController.GetAccountAsync (FlexToEcocash)'
[02:54:03 INF] Request finished in 426.0567ms 200 application/json; charset=utf-8
[02:54:03 WRN] Span has already been finished; will not be reported again. Operation: HTTP GET Trace Id: c976e25bf21bfae5 Span Id: c976e25bf21bfae5
What am I missing ?
kubernetes
asp.net-core-webapi
zipkin
jaeger
k0s
0 Answers
Your Answer