Skip to content

Commit

Permalink
Added span attributes for data.city and data.country to cover cases w…
Browse files Browse the repository at this point in the history
…here country is not populated as a param but still valuable for trace searches.
  • Loading branch information
daveknapik committed Apr 23, 2024
1 parent b53b02d commit 2b34b76
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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:
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions app/controllers/forecasts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down

0 comments on commit 2b34b76

Please sign in to comment.