Skip to content

Commit

Permalink
Custom attributes and spans for FeatureFlag service (#371)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshleecreates authored Sep 19, 2022
1 parent 542ee3b commit b9dd425
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,5 @@ significant modifications will be credited to OpenTelemetry Authors.
([#345](https://github.com/open-telemetry/opentelemetry-demo/pull/345))
* Improve initial run time, without a build
([#362](https://github.com/open-telemetry/opentelemetry-demo/pull/362))
* Add custom span and custom span attributes for Feature Flag Service
([#371](https://github.com/open-telemetry/opentelemetry-demo/pull/371))
6 changes: 4 additions & 2 deletions docs/manual_span_attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ This document contains the list of manual Span Attributes used throughout the de
## FeatureFlagService

| Name | Type | Description |
|-----------|------|-------------|
| None yet | | |
|-------------------------------|---------|--------------------------|
| `app.featureflag.name` | string | Name of the feature flag |
| `app.featureflag.description` | string | Admin description |
| `app.featureflag.enabled` | boolean | The feature flag status | |

## Frontend

Expand Down
2 changes: 1 addition & 1 deletion docs/trace_service_features.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Emoji Legend
| Checkout | Go | :100: | :100: | :100: | :no_bell: | :no_bell: | :no_bell: |
| Currency | C++ | :no_bell: | :100: | :100: | :100: | :no_bell: | :no_bell: |
| Email | Ruby | :100: | :100: | :100: | :no_bell: | :no_bell: | :no_bell: |
| Feature Flag | Erlang / Elixir | :100: | :construction: | :construction: | :no_bell: | :no_bell: | :no_bell: |
| Feature Flag | Erlang / Elixir | :100: | :100: | :100: | :no_bell: | :no_bell: | :no_bell: |
| Frontend | JavaScript | :100: | :100: | :100: | :no_bell: | :100: | :100: |
| Payment | JavaScript | :100: | :100: | :100: | :no_bell: | :no_bell: | :100: |
| Product Catalog | Go | :100: | :no_bell: | :100: | :no_bell: | :no_bell: | :no_bell: |
Expand Down
17 changes: 14 additions & 3 deletions src/featureflagservice/lib/featureflagservice/feature_flags.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ defmodule Featureflagservice.FeatureFlags do
"""

import Ecto.Query, warn: false

require OpenTelemetry.Tracer

alias Featureflagservice.Repo

alias Featureflagservice.FeatureFlags.FeatureFlag
Expand Down Expand Up @@ -64,9 +67,17 @@ defmodule Featureflagservice.FeatureFlags do
"""
def create_feature_flag(attrs \\ %{}) do
%FeatureFlag{}
|> FeatureFlag.changeset(attrs)
|> Repo.insert()
{function_name, arity} = __ENV__.function
OpenTelemetry.Tracer.with_span "featureflagservice.featureflags.#{function_name}/#{arity}" do
OpenTelemetry.Tracer.set_attributes(%{
"app.featureflag.name" => attrs["name"],
"app.featureflag.description" => attrs["description"],
"app.featureflag.enabled" => attrs["enabled"]
})
%FeatureFlag{}
|> FeatureFlag.changeset(attrs)
|> Repo.insert()
end
end

@doc """
Expand Down
4 changes: 4 additions & 0 deletions src/featureflagservice/src/ffs_service.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

-include_lib("grpcbox/include/grpcbox.hrl").

-include_lib("opentelemetry_api/include/otel_tracer.hrl").

-spec get_flag(ctx:t(), ffs_demo_pb:get_flag_request()) ->
{ok, ffs_demo_pb:get_flag_response(), ctx:t()} | grpcbox_stream:grpc_error_response().
get_flag(Ctx, #{name := Name}) ->
Expand All @@ -22,6 +24,8 @@ get_flag(Ctx, #{name := Name}) ->
inserted_at := CreatedAt,
updated_at := UpdatedAt
} ->
?set_attribute('app.featureflag.name', Name),
?set_attribute('app.featureflag.enabled', Enabled),
{ok, Epoch} = 'Elixir.NaiveDateTime':from_erl({{1970, 1, 1}, {0, 0, 0}}),
CreatedAtSeconds = 'Elixir.NaiveDateTime':diff(CreatedAt, Epoch),
UpdatedAtSeconds = 'Elixir.NaiveDateTime':diff(UpdatedAt, Epoch),
Expand Down

0 comments on commit b9dd425

Please sign in to comment.