From 2b34b76bf57a3f7bc44f1ed54e31b8c9b56b91d6 Mon Sep 17 00:00:00 2001 From: Dave Knapik Date: Wed, 24 Apr 2024 00:03:14 +0900 Subject: [PATCH] Added span attributes for data.city and data.country to cover cases where country is not populated as a param but still valuable for trace searches. --- README.md | 24 ++++++++++++++---------- app/controllers/forecasts_controller.rb | 1 + 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 514fd74..99f878e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ -# README +# TC Weather API -This README would normally document whatever steps are necessary to get the -application up and running. +An overview of the application, its purpose, and potential use cases ## Prerequisites @@ -14,6 +13,12 @@ application up and running. ## Running the app locally +TODO: A simple guide on how to set up and run the application locally + +### Without telemetry + +Good old-fashioned `rails s` + ### With telemetry, sent to console You can run the app locally with telemetry output sent to console like so: @@ -56,13 +61,12 @@ OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318 \ rails server ``` -## Sample calls +## API docs -http://localhost:8080/forecasts/Springfield?state=MO&country=US +TODO: API endpoint, request/response formats, and examples of usage + +### Usage examples ---- +http://localhost:8080/forecasts/Springfield?state=MO&country=US -- System dependencies -- How to run the test suite -- Services (job queues, cache servers, search engines, etc.) -- Deployment instructions +## Recommendations on how the API could be improved or extended to cater to a broader audience diff --git a/app/controllers/forecasts_controller.rb b/app/controllers/forecasts_controller.rb index 9878411..1691d35 100644 --- a/app/controllers/forecasts_controller.rb +++ b/app/controllers/forecasts_controller.rb @@ -10,6 +10,7 @@ def show @data = @open_weather_client.current_weather(forecast_params.merge(units: 'metric')) @calculate_api_call_duration = -> { span.end_timestamp - span.start_timestamp } end + @current_span.add_attributes('data.city' => @data.name, 'data.country' => @data.sys.country) rescue Faraday::ResourceNotFound => e @data = { error: "Location not found: #{forecast_params.values.join(', ')}", status: 404 } @current_span.status = OpenTelemetry::Trace::Status.error(@data[:error])