Skip to content

Commit

Permalink
Conversion to TrackJS (#1)
Browse files Browse the repository at this point in the history
Use the existing implementation as a framework, but ultimately re-write quite a bit to make things work (and make sense) with TrackJS.

* Update LICENSE with Scrive AB
* Change naming from Rollbar to TrackJS
* Change toJsonBody to TrackJS schema
* Change metadata from (String, Value) to TrackJS more limited (String, String)
* Remove Environment and Scope, TrackJS has an Application instead
* Remove retry on rate limit throttle and fix/improve documentation
  TrackJS does have a rate limit, but it unfortunately does not error,
  they requests are simply dropped.
* Adjust example implementation and build to CI
* Add `Context` to provide some optional extra information
* Remove Levels and `console`: not very useful for TrackJS
* Add `Report` type to include message plus Scope information
* Improve documentation
* Add simple version match test
  • Loading branch information
jonathanjouty authored Mar 26, 2024
1 parent 515f8e4 commit 48c38cd
Show file tree
Hide file tree
Showing 12 changed files with 555 additions and 426 deletions.
18 changes: 17 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,20 @@ jobs:
- uses: jorelali/setup-elm@v2
with:
elm-version: 0.19.1
- run: elm make src/Rollbar.elm
- run: elm make src/TrackJS.elm

build-example:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: jorelali/setup-elm@v2
with:
elm-version: 0.19.1
- run: elm make Example.elm
working-directory: ./example

check-versions-match:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: ./test-version.sh
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
BSD 3-Clause License

Copyright (c) 2018, NoRedInk
Copyright (c) 2020, Scrive AB
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,23 @@

**Work in Progress:** This project is a fork of `elm-rollbar`, with the
intention of adapting it to work with TrackJS.

TODOs:
- [x] Add example implementation (will also function as a live test)
- [x] Test that it works!
- [x] Add optional `Context` to include useful things
- [x] Get rid of console and levels: does not seem very useful for TrackJS
- [x] Add `Scope` to include `url` and "stack trace", anything else?
- [x] Figure out what to include in `customer` data, in particular, the various `id`s
- [x] Add test for version staying in sync
- [ ] Finish and check documentation
- [ ] Publish!

Possible extra features not currently implemented:
- Explore how maximum payload size and HTTP 413 response can be handled
(without encumbering the API).
An idea would be to trim values to a fixed "long enough" length for each
field, compute how much of the 100 kB we have left, and then trim rest of
stackTrace.
- Optional `console` events
- Optional `network` telemetry information
12 changes: 7 additions & 5 deletions elm.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"type": "package",
"name": "NoRedInk/elm-rollbar",
"summary": "Send reports to Rollbar",
"name": "scrive/elm-trackjs",
"summary": "Send reports to TrackJS",
"license": "BSD-3-Clause",
"version": "2.0.1",
"version": "3.10.4",
"exposed-modules": [
"Rollbar"
"TrackJS"
],
"elm-version": "0.19.0 <= v < 0.20.0",
"dependencies": {
Expand All @@ -14,7 +14,9 @@
"elm/http": "2.0.0 <= v < 3.0.0",
"elm/json": "1.0.0 <= v < 2.0.0",
"elm/random": "1.0.0 <= v < 2.0.0",
"elm/time": "1.0.0 <= v < 2.0.0"
"elm/time": "1.0.0 <= v < 2.0.0",
"elm/url": "1.0.0 <= v < 2.0.0",
"rtfeldman/elm-iso8601-date-strings": "1.1.4 <= v < 2.0.0"
},
"test-dependencies": {}
}
72 changes: 40 additions & 32 deletions example/Example.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,29 @@ import Dict
import Html exposing (..)
import Html.Attributes exposing (value)
import Html.Events exposing (onClick, onInput)
import Json.Encode
import Rollbar exposing (Rollbar)
import Task
import Time
import TrackJS exposing (TrackJS)


token : String
token =
-- This is a demo token provide by Rollbar for its demo user
-- You view and verify the result by visiting https://rollbar.com/demo/demo/
-- This will log you in as the demo user, if you are not already logged in.
"3cda8fbafbfe4a6599d1954b1f1a246e"
-- NOTE: TrackJS does not seem to have a demo token, so you need to use a valid one.
-- Please make sure to create the application in TrackJS before you try this example.
Debug.todo "00000000000000000000000000000000"


rollbar : Rollbar
rollbar =
Rollbar.scoped
(Rollbar.token token)
(Rollbar.codeVersion "0.0.1")
(Rollbar.environment "test")
"Example"
trackJsWithStartTime : Maybe Time.Posix -> TrackJS
trackJsWithStartTime time =
let
context =
TrackJS.emptyContext
in
TrackJS.reporter
(TrackJS.token token)
(TrackJS.codeVersion "0.0.1")
(TrackJS.application "elm-trackjs-example")
{ context | startTime = time }



Expand All @@ -33,12 +36,14 @@ rollbar =

type alias Model =
{ report : String
, trackJS : TrackJS
}


initialModel : Model
initialModel =
{ report = ""
{ report = "Example report"
, trackJS = trackJsWithStartTime Nothing
}


Expand All @@ -47,32 +52,35 @@ initialModel =


type Msg
= SetText String
| NoOp
= StartTime Time.Posix
| SetText String
| Send
| NoOp


update : Msg -> Model -> ( Model, Cmd Msg )
update msg model =
case msg of
NoOp ->
( model, Cmd.none )
StartTime time ->
( { model | trackJS = trackJsWithStartTime (Just time) }, Cmd.none )

SetText text ->
( { model | report = text }, Cmd.none )

Send ->
( model, info model.report )
( model, report model.trackJS model.report )


info : String -> Cmd Msg
info report =
Task.attempt (\_ -> NoOp) (rollbar.info report Dict.empty)
NoOp ->
( model, Cmd.none )


json : Json.Encode.Value
json =
Json.Encode.object [ ( "environment", Json.Encode.string "test" ) ]
report : TrackJS -> String -> Cmd Msg
report trackJS message =
Task.attempt (\_ -> NoOp)
(trackJS.report
{ message = message, url = "elm-trackjs-example/home", stackTrace = Nothing }
(Dict.singleton "eg-key" "eg-value")
)



Expand All @@ -83,7 +91,7 @@ view : Model -> Html Msg
view model =
div []
[ input [ onInput SetText, value model.report ] []
, button [ onClick Send ] [ text "Send to rollbar" ]
, button [ onClick Send ] [ text "Send to TrackJS" ]
]


Expand All @@ -94,13 +102,13 @@ view model =
main : Program () Model Msg
main =
Browser.document
{ init = \_ -> init
, subscriptions = \_ -> Sub.none
{ init = always init
, subscriptions = always Sub.none
, update = update
, view = \model -> { title = "Example", body = [ view model ] }
, view = \model -> { title = "Elm TrackJS Example", body = [ view model ] }
}


init : ( Model, Cmd msg )
init : ( Model, Cmd Msg )
init =
( initialModel, Cmd.none )
( initialModel, Task.perform StartTime Time.now )
18 changes: 10 additions & 8 deletions example/elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,26 @@
".",
"../src"
],
"elm-version": "0.19.0",
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"danyx23/elm-uuid": "2.1.2",
"elm/browser": "1.0.1",
"elm/core": "1.0.2",
"elm/browser": "1.0.2",
"elm/core": "1.0.5",
"elm/html": "1.0.0",
"elm/http": "2.0.0",
"elm/json": "1.1.3",
"elm/random": "1.0.0",
"elm/time": "1.0.0"
"elm/time": "1.0.0",
"elm/url": "1.0.0",
"rtfeldman/elm-iso8601-date-strings": "1.1.4"
},
"indirect": {
"elm/regex": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.2",
"elm/bytes": "1.0.8",
"elm/file": "1.0.4"
"elm/file": "1.0.5",
"elm/parser": "1.1.0",
"elm/regex": "1.0.0",
"elm/virtual-dom": "1.0.3"
}
},
"test-dependencies": {
Expand Down
6 changes: 3 additions & 3 deletions scripts/verify-notifier-version.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/usr/bin/env sh

version_in_elm_package_json=$(cat elm.json | jq -M .version)
version_in_internal=$(cat src/Rollbar/Internal.elm | pcregrep -M "version =\n $version_in_elm_package_json" | grep $version_in_elm_package_json | tr -d '[:space:]')
version_in_internal=$(cat src/TrackJS/Internal.elm | pcregrep -M "version =\n $version_in_elm_package_json" | grep $version_in_elm_package_json | tr -d '[:space:]')


if [ "${version_in_elm_package_json}" != "${version_in_internal}" ]; then
echo "The value specified in Rollbar.Internal.version is not the same as the package version in elm.json. Please update it before publishing!"
echo "The value specified in TrackJS.Internal.version is not the same as the package version in elm.json. Please update it before publishing!"
exit 1
else
echo "Rollbar.Internal.version matches version in elm.json"
echo "TrackJS.Internal.version matches version in elm.json"
exit 0
fi
Loading

0 comments on commit 48c38cd

Please sign in to comment.