-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from shogo82148/implement-ecs-plugin
implement ecs plugin
- Loading branch information
Showing
2 changed files
with
48 additions
and
0 deletions.
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package ecs | ||
|
||
import ( | ||
"os" | ||
"strings" | ||
|
||
"github.com/shogo82148/aws-xray-yasdk-go/xray" | ||
"github.com/shogo82148/aws-xray-yasdk-go/xray/schema" | ||
) | ||
|
||
type plugin struct { | ||
ECS *schema.ECS | ||
} | ||
|
||
// Init activates ECS Plugin at runtime. | ||
func Init() { | ||
uri := os.Getenv("ECS_CONTAINER_METADATA_URI") | ||
if !strings.HasPrefix(uri, "http://") { | ||
return | ||
} | ||
hostname, err := os.Hostname() | ||
if err != nil { | ||
return | ||
} | ||
xray.AddPlugin(&plugin{ | ||
ECS: &schema.ECS{ | ||
Container: hostname, | ||
}, | ||
}) | ||
} | ||
|
||
// HandleSegment implements Plugin. | ||
func (p *plugin) HandleSegment(seg *xray.Segment, doc *schema.Segment) { | ||
if doc.AWS == nil { | ||
doc.AWS = schema.AWS{} | ||
} | ||
doc.AWS.SetECS(p.ECS) | ||
} | ||
|
||
// Origin implements Plugin. | ||
func (*plugin) Origin() string { return schema.OriginECSContainer } |
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,7 @@ | ||
package init | ||
|
||
import "github.com/shogo82148/aws-xray-yasdk-go/plugins/ecs" | ||
|
||
func init() { | ||
ecs.Init() | ||
} |