Skip to content

Instantly share code, notes, and snippets.

View maplebed's full-sized avatar

Ben Hartshorne maplebed

View GitHub Profile
package log
import (
"io"
libhoney "github.com/honeycombio/libhoney"
)
type hnyLogger struct {
}
@maplebed
maplebed / update.sh
Created January 1, 2018 01:26
today's adventure in iterating on a lambda python playground
#!/bin/bash
num=$(grep playver index.py | grep -E -o '[0-9]+')
newnum=$((num+1))
echo https://s3.amazonaws.com/mybucket/testlambda/archive${newnum}.zip
sed -i -e "s/= ${num}$/= ${newnum}/" index.py
python make-archive.py
aws s3 cp archive.zip s3://mybucket/testlambda/archive${newnum}.zip
aws lambda update-function-code --function-name testlambda_playground --s3-bucket mybucket --s3-key testlambda/archive${newnum}.zip
wk = node[:honeycomb][:writekey]
n = node
Chef.event_handler do
Chef::Client.when_run_completes_successfully {|run_status| @handler.instance_variable_set(:@run_status, run_status) }
Chef::Client.when_run_fails {|run_status| @handler.instance_variable_set(:@run_status, run_status) }
::Honeycomb.init(wk)
on :run_completed do
puts "run_completed handler"
require "net/http"
require "uri"
require "openssl"
require "json"
class Honeycomb
def self.report(run_status)
api_data = {
"node.name" => run_status.node.name,
"start_time" => run_status.start_time,
@maplebed
maplebed / libhoney_sinatra_example.rb
Last active October 7, 2017 23:55
A sample sinatra app sending events to Honeycomb
require 'sinatra'
require 'libhoney'
configure do
set :honeycomb, Libhoney::Client.new(writekey: "abc123redacteddef456", dataset: 'rubytest')
end
before do
@ev = settings.honeycomb.event()
@ev.add_field("url", request.url)
@maplebed
maplebed / libhoney_ruby_example.rb
Last active October 7, 2017 23:55
Shortest possible libhoney use
require 'libhoney'
honeycomb = Libhoney::Client.new(writekey: "abc123redacteddef456", dataset: 'rubytest')
data = {}
data[:test] = "Data!"
honeycomb.send_now(data)
honeycomb.close(true)
@maplebed
maplebed / libhoney_example.go
Created September 26, 2017 18:11
Wrapping a request with libhoney
func (a *App) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
// we wrap the writer to gain access to the status field later
w := api.NewResponseWrapper(writer)
builder := libhoney.NewBuilder()
// we wrap libhoney in an interface to abstract events vs. builders
hnyWrapper := &libhoneyWrapper{builder: builder}
// Embed the libhoney wrapper in a context to give the rest of the code access
ctx := context.WithValue(request.Context(), CtxKeyLibhoney, hnyWrapper)
r := request.WithContext(ctx)
@maplebed
maplebed / aoeu.go
Last active August 3, 2017 23:01
aoeu
aoeu
aoeu
aoeu
oaeuaoeu
@maplebed
maplebed / main.out
Last active March 25, 2017 21:58
Output from logfmt lib
➜ go run main.go
0: `foo=bar` // correct
(map[string]interface {}) (len=1) {
(string) (len=3) "foo": (string) (len=3) "bar"
}
1: `foo=bar baz=3 fl=3.1415926535 bl=true` // correct
(map[string]interface {}) (len=4) {
(string) (len=2) "bl": (bool) true,
(string) (len=3) "foo": (string) (len=3) "bar",
(string) (len=3) "baz": (int) 3,
@maplebed
maplebed / main.go
Created March 25, 2017 21:55
Playing with logfmt go k=v parser library
package main
import (
"fmt"
"strconv"
"github.com/davecgh/go-spew/spew"
"github.com/kr/logfmt"
)