Skip to content

Commit

Permalink
[resourcedetectionprocessor] map heroku env vars according to specifi…
Browse files Browse the repository at this point in the history
…cation mapping (#18873)
  • Loading branch information
atoulme authored Feb 28, 2023
1 parent b40e984 commit 73cb631
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
16 changes: 16 additions & 0 deletions .chloggen/update-heroku-mappings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: resourcedetectionprocessor

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Update Heroku mappings to match specification

# One or more tracking issues related to the change
issues: [18872]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
14 changes: 4 additions & 10 deletions processor/resourcedetectionprocessor/internal/heroku/heroku.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,12 @@ const (
// TypeStr is type of detector.
TypeStr = "heroku"

// The identifier for the current release
herokuReleaseVersion = "heroku.release.version"
// The time and date the release was created.
herokuReleaseCreationTimestamp = "heroku.release.creation_timestamp"
// The commit hash for the current release
herokuReleaseCommit = "heroku.release.commit"
// The application name
herokuAppName = "heroku.app.name"
// The unique identifier for the application
herokuAppID = "heroku.app.id"
// The dyno identifier. Used as host name
herokuDynoID = "heroku.dyno.id"
)

// NewDetector returns a detector which can detect resource attributes on Heroku
Expand All @@ -65,20 +59,20 @@ func (d *detector) Detect(ctx context.Context) (resource pcommon.Resource, schem
}

attrs := res.Attributes()
attrs.PutStr(conventions.AttributeCloudProvider, "heroku")

attrs.PutStr(herokuDynoID, dynoID)
attrs.PutStr(conventions.AttributeHostName, dynoID)
attrs.PutStr(conventions.AttributeServiceInstanceID, dynoID)
if v, ok := os.LookupEnv("HEROKU_APP_ID"); ok {
attrs.PutStr(herokuAppID, v)
}
if v, ok := os.LookupEnv("HEROKU_APP_NAME"); ok {
attrs.PutStr(herokuAppName, v)
attrs.PutStr(conventions.AttributeServiceName, v)
}
if v, ok := os.LookupEnv("HEROKU_RELEASE_CREATED_AT"); ok {
attrs.PutStr(herokuReleaseCreationTimestamp, v)
}
if v, ok := os.LookupEnv("HEROKU_RELEASE_VERSION"); ok {
attrs.PutStr(herokuReleaseVersion, v)
attrs.PutStr(conventions.AttributeServiceVersion, v)
}
if v, ok := os.LookupEnv("HEROKU_SLUG_COMMIT"); ok {
attrs.PutStr(herokuReleaseCommit, v)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ func TestDetectTrue(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, map[string]any{
"heroku.app.id": "appid",
"heroku.app.name": "appname",
"heroku.dyno.id": "foo",
"service.name": "appname",
"service.instance.id": "foo",
"heroku.release.commit": "23456",
"heroku.release.creation_timestamp": "createdat",
"heroku.release.version": "v1",
"host.name": "foo",
"service.version": "v1",
"cloud.provider": "heroku",
},
res.Attributes().AsRaw())
}
Expand All @@ -68,11 +68,11 @@ func TestDetectTruePartial(t *testing.T) {
assert.Equal(t, conventions.SchemaURL, schemaURL)
require.NoError(t, err)
assert.Equal(t, map[string]any{
"heroku.app.id": "appid",
"heroku.app.name": "appname",
"heroku.dyno.id": "foo",
"heroku.release.version": "v1",
"host.name": "foo",
"heroku.app.id": "appid",
"service.name": "appname",
"service.instance.id": "foo",
"service.version": "v1",
"cloud.provider": "heroku",
},
res.Attributes().AsRaw())
}
Expand Down

0 comments on commit 73cb631

Please sign in to comment.