-
-
Notifications
You must be signed in to change notification settings - Fork 313
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
Xray initial support #273
base: master
Are you sure you want to change the base?
Xray initial support #273
Changes from 5 commits
276782e
27e1d98
852d35b
1ea38d8
4367ddd
ed2fa69
245d7f7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/aws/aws-lambda-go/events" | ||
"github.com/aws/aws-lambda-go/lambda" | ||
"github.com/aws/aws-sdk-go/aws/endpoints" | ||
"github.com/aws/aws-xray-sdk-go/strategy/ctxmissing" | ||
"github.com/aws/aws-xray-sdk-go/xray" | ||
"github.com/cristim/autospotting/core" | ||
"github.com/cristim/ec2-instances-info" | ||
"github.com/namsral/flag" | ||
|
@@ -26,12 +28,11 @@ func main() { | |
if os.Getenv("AWS_LAMBDA_FUNCTION_NAME") != "" { | ||
lambda.Start(Handler) | ||
} else { | ||
run() | ||
run(context.Background()) | ||
} | ||
} | ||
|
||
func run() { | ||
|
||
func run(ctx context.Context) { | ||
log.Println("Starting autospotting agent, build", Version) | ||
|
||
log.Printf("Parsed command line flags: "+ | ||
|
@@ -58,7 +59,11 @@ func run() { | |
conf.TagFilteringMode, | ||
conf.SpotProductDescription) | ||
|
||
autospotting.Run(conf.Config) | ||
xray.Configure(xray.Config{ | ||
ContextMissingStrategy: ctxmissing.NewDefaultLogErrorStrategy(), | ||
LogLevel: "error", | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be configurable from an env variable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What exactly do you want to configure in this place? Log level? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I made log level configurable via flag, but it looks like there is a bug in X-Ray SDK. aws/aws-xray-sdk-go#60. At the moment, it will post a particular error message ignoring log level... |
||
autospotting.Run(ctx, conf.Config) | ||
log.Println("Execution completed, nothing left to do") | ||
} | ||
|
||
|
@@ -87,8 +92,8 @@ func init() { | |
} | ||
|
||
// Handler implements the AWS Lambda handler | ||
func Handler(request events.APIGatewayProxyRequest) { | ||
run() | ||
func Handler(ctx context.Context) { | ||
run(ctx) | ||
} | ||
|
||
// Configuration handling | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks much better than I had attempted... I'm just sorry I wasted a few hours trying to fix this myself without any results.
I'll try it out tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worked like a charm!