Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement beanstalk plugin #47

Merged
merged 1 commit into from
Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions plugins/beanstalk/beanstalk.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package beanstalk

import (
"context"
"encoding/json"
"os"
"runtime"
"time"

"github.com/shogo82148/aws-xray-yasdk-go/xray"
"github.com/shogo82148/aws-xray-yasdk-go/xray/schema"
"github.com/shogo82148/aws-xray-yasdk-go/xray/xraylog"
)

const configPath = "/var/elasticbeanstalk/xray/environment.conf"

type plugin struct {
ElasticBeanstalk *schema.ElasticBeanstalk
}

// Init activates ECS Plugin at runtime.
func Init() {
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

if runtime.GOOS != "linux" {
return
}

f, err := os.Open(configPath)
if err != nil {
// it seems not to be in Elastic Beanstalk environment.
// just ignore error.
xraylog.Debugf(ctx, "failed to read %q: %v", configPath, err)
return
}
defer f.Close()

var conf schema.ElasticBeanstalk
dec := json.NewDecoder(f)
if err := dec.Decode(&conf); err != nil {
xraylog.Debugf(ctx, "failed to decode: %v", err)
return
}
xray.AddPlugin(&plugin{
ElasticBeanstalk: &conf,
})
}

// HandleSegment implements Plugin.
func (p *plugin) HandleSegment(seg *xray.Segment, doc *schema.Segment) {
if doc.AWS == nil {
doc.AWS = schema.AWS{}
}
doc.AWS.SetElasticBeanstalk(p.ElasticBeanstalk)
}

// Origin implements Plugin.
func (*plugin) Origin() string { return schema.OriginElasticBeanstalk }
7 changes: 7 additions & 0 deletions plugins/beanstalk/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/beanstalk"

func init() {
beanstalk.Init()
}