Skip to content

Commit

Permalink
Merge pull request #44 from shogo82148/implement-ecs-plugin
Browse files Browse the repository at this point in the history
implement ecs plugin
  • Loading branch information
shogo82148 authored Mar 31, 2020
2 parents e211cfc + f7f83d5 commit bf6e396
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
41 changes: 41 additions & 0 deletions plugins/ecs/ecs.go
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 }
7 changes: 7 additions & 0 deletions plugins/ecs/init/init.go
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()
}

0 comments on commit bf6e396

Please sign in to comment.