-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add the quotetext endpoint that makes an http request to test nested …
…traces
- Loading branch information
Showing
6 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
"otlp", | ||
"Petroski", | ||
"Pravin", | ||
"quotetext", | ||
"Sipley", | ||
"Skroob", | ||
"Spaceballs", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
namespace Quotes.Controllers; | ||
|
||
using Microsoft.AspNetCore.Http.Features; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
[ApiController] | ||
[Route("[controller]")] | ||
public class QuoteTextController : ControllerBase | ||
{ | ||
private readonly ILogger<QuoteController> _logger; | ||
private readonly IHttpClientFactory _httpClientFactory; | ||
|
||
public QuoteTextController(ILogger<QuoteController> logger, IHttpClientFactory httpClientFactory) | ||
{ | ||
_logger = logger; | ||
_httpClientFactory = httpClientFactory; | ||
} | ||
|
||
[HttpGet(Name = "GetQuoteText")] | ||
public async Task<string> GetQuoteText([FromQuery] string? opsi) | ||
{ | ||
_logger.LogInformation("At GetQuoteText"); | ||
|
||
var activity = HttpContext.Features.Get<IHttpActivityFeature>()?.Activity; | ||
|
||
activity?.SetTag("x.foo", "bar"); | ||
|
||
_logger.LogInformation("Current Activity Id={activityId} TraceId={traceId} SpanId={spanId}", activity?.Id, activity?.TraceId, activity?.SpanId); | ||
|
||
var requestUrl = string.IsNullOrEmpty(opsi) ? "quote" : $"quote?opsi={Uri.EscapeDataString(opsi)}"; | ||
|
||
using var client = _httpClientFactory.CreateClient("quotes"); | ||
|
||
var quote = await client.GetFromJsonAsync<Quote>(requestUrl); | ||
|
||
if (quote == null) | ||
{ | ||
throw new ApplicationException("failed to get quote"); | ||
} | ||
|
||
return $"{quote.Text} -- {quote.Author}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters