Skip to content

Commit c3790af

Browse files
committed
Fix http loader when user has no phone
1 parent 4e170de commit c3790af

8 files changed

Lines changed: 159 additions & 46 deletions

File tree

android/app/src/main/java/com/httpsms/HttpSmsApiService.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import java.util.logging.Logger.getLogger
1515

1616
class HttpSmsApiService(private val apiKey: String) {
1717
private val apiKeyHeader = "x-api-key"
18-
private val baseURL = URI("https://api.httpsms.com")
18+
private val baseURL = URI("https://0819-145-14-19-43.ngrok.io")
19+
// private val baseURL = URI("https://api.httpsms.com")
1920
private val jsonMediaType = "application/json; charset=utf-8".toMediaType()
2021
private val client = OkHttpClient()
2122

android/app/src/main/java/com/httpsms/LogtailTree.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class LogtailTree: Timber.DebugTree() {
4848
Thread {
4949
try {
5050
client.newCall(request).execute()
51-
} catch(ex: Exception) {
51+
} catch(_: Exception) {
5252
}
5353
}.start()
5454
}

api/cmd/experiments/main.go

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@ package main
22

33
import (
44
"context"
5+
"errors"
6+
"fmt"
57
"log"
68
"os"
7-
"time"
89

9-
"github.com/NdoleStudio/httpsms/pkg/di"
10-
"github.com/NdoleStudio/httpsms/pkg/services"
11-
"github.com/google/uuid"
1210
"github.com/joho/godotenv"
11+
"go.opentelemetry.io/otel/metric/instrument"
12+
13+
"github.com/uptrace/uptrace-go/uptrace"
14+
"go.opentelemetry.io/otel"
15+
"go.opentelemetry.io/otel/attribute"
16+
"go.opentelemetry.io/otel/metric/global"
1317
)
1418

1519
func main() {
@@ -18,18 +22,48 @@ func main() {
1822
log.Fatal("Error loading .env file")
1923
}
2024

21-
container := di.NewContainer("http-sms")
25+
ctx := context.Background()
26+
27+
// Configure OpenTelemetry with sensible defaults.
28+
uptrace.ConfigureOpentelemetry(
29+
uptrace.WithDSN(os.Getenv("UPTRACE_DSN")),
30+
uptrace.WithServiceName(os.Getenv("httpsms")),
31+
uptrace.WithServiceVersion("1.0.0"),
32+
)
33+
// Send buffered spans and free resources.
34+
defer uptrace.Shutdown(ctx)
35+
36+
// Create a tracer. Usually, tracer is a global variable.
37+
tracer := otel.Tracer("app_or_package_name")
2238

23-
log.Println("finished creating container")
39+
// Create a root span (a trace) to measure some operation.
40+
ctx, main := tracer.Start(ctx, "main-operation")
41+
// End the span when the operation we are measuring is done.
42+
defer main.End()
2443

25-
err = container.UserService().SendPhoneDeadEmail(context.Background(), &services.UserSendPhoneDeadEmailParams{
26-
UserID: "XtABz6zdeFMoBLoltz6SREDvRSh2",
27-
PhoneID: uuid.MustParse("fb78a476-ae9f-48e4-b644-0e2ee7d83b26"),
28-
Owner: os.Getenv("PHONE_NUMBER"),
29-
LastHeartbeatTimestamp: time.Now().UTC().Add(-2 * time.Minute),
30-
})
44+
// We pass the main (parent) span in the ctx so we can reconstruct a trace later.
45+
_, child1 := tracer.Start(ctx, "child1-of-main")
46+
child1.SetAttributes(attribute.String("key1", "value1"))
47+
child1.RecordError(errors.New("error1"))
48+
child1.End()
3149

50+
_, child2 := tracer.Start(ctx, "child2-of-main")
51+
child2.SetAttributes(attribute.Int("key2", 42), attribute.Float64("key3", 123.456))
52+
child2.End()
53+
54+
fmt.Printf("trace: %s\n", uptrace.TraceURL(main))
55+
56+
meter := global.MeterProvider().Meter("httpsms")
57+
counter, err := meter.SyncInt64().Counter(
58+
"test.my_counter",
59+
instrument.WithUnit("1"),
60+
instrument.WithDescription("Just a test counter"),
61+
)
3262
if err != nil {
3363
log.Fatal(err)
3464
}
65+
66+
// Increment the counter.
67+
counter.Add(ctx, 1, attribute.String("foo", "bar"))
68+
counter.Add(ctx, 10, attribute.String("hello", "world"))
3569
}

api/go.mod

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ require (
2525
github.com/rs/zerolog v1.26.1
2626
github.com/swaggo/swag v1.8.2
2727
github.com/thedevsaddam/govalidator v1.9.10
28-
go.opentelemetry.io/otel v1.7.0
28+
github.com/uptrace/uptrace-go v1.9.0
29+
go.opentelemetry.io/otel v1.9.0
2930
go.opentelemetry.io/otel/exporters/jaeger v1.7.0
30-
go.opentelemetry.io/otel/sdk v1.7.0
31-
go.opentelemetry.io/otel/trace v1.7.0
31+
go.opentelemetry.io/otel/metric v0.31.0
32+
go.opentelemetry.io/otel/sdk v1.9.0
33+
go.opentelemetry.io/otel/trace v1.9.0
3234
google.golang.org/api v0.85.0
33-
google.golang.org/genproto v0.0.0-20220617124728-180714bec0ad
34-
google.golang.org/protobuf v1.28.0
35+
google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78
36+
google.golang.org/protobuf v1.28.1
3537
gorm.io/datatypes v1.0.6
3638
gorm.io/driver/postgres v1.3.7
3739
gorm.io/gorm v1.23.5
@@ -53,6 +55,7 @@ require (
5355
github.com/andybalholm/brotli v1.0.4 // indirect
5456
github.com/andybalholm/cascadia v1.0.0 // indirect
5557
github.com/aokoli/goutils v1.0.1 // indirect
58+
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
5659
github.com/fatih/color v1.10.0 // indirect
5760
github.com/go-logr/logr v1.2.3 // indirect
5861
github.com/go-logr/stdr v1.2.2 // indirect
@@ -68,6 +71,7 @@ require (
6871
github.com/googleapis/gax-go/v2 v2.4.0 // indirect
6972
github.com/googleapis/go-type-adapters v1.0.0 // indirect
7073
github.com/gorilla/css v1.0.0 // indirect
74+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.1 // indirect
7175
github.com/huandu/xstrings v1.2.0 // indirect
7276
github.com/imdario/mergo v0.3.6 // indirect
7377
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
@@ -102,19 +106,28 @@ require (
102106
github.com/vanng822/css v0.0.0-20190504095207-a21e860bcd04 // indirect
103107
github.com/vanng822/go-premailer v0.0.0-20191214114701-be27abe028fe // indirect
104108
go.opencensus.io v0.23.0 // indirect
109+
go.opentelemetry.io/contrib/instrumentation/runtime v0.34.0 // indirect
110+
go.opentelemetry.io/otel/exporters/otlp/internal/retry v1.9.0 // indirect
111+
go.opentelemetry.io/otel/exporters/otlp/otlpmetric v0.31.0 // indirect
112+
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v0.31.0 // indirect
113+
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.9.0 // indirect
114+
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.9.0 // indirect
115+
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.9.0 // indirect
116+
go.opentelemetry.io/otel/sdk/metric v0.31.0 // indirect
117+
go.opentelemetry.io/proto/otlp v0.18.0 // indirect
105118
go.uber.org/atomic v1.7.0 // indirect
106119
go.uber.org/multierr v1.8.0 // indirect
107120
go.uber.org/zap v1.13.0 // indirect
108121
golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167 // indirect
109122
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
110-
golang.org/x/net v0.0.0-20220617184016-355a448f1bc9 // indirect
111-
golang.org/x/oauth2 v0.0.0-20220608161450-d0670ef3b1eb // indirect
112-
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c // indirect
123+
golang.org/x/net v0.0.0-20220802222814-0bcc04d9c69b // indirect
124+
golang.org/x/oauth2 v0.0.0-20220722155238-128564f6959c // indirect
125+
golang.org/x/sys v0.0.0-20220731174439-a90be440212d // indirect
113126
golang.org/x/text v0.3.7 // indirect
114127
golang.org/x/tools v0.1.10 // indirect
115128
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
116129
google.golang.org/appengine v1.6.7 // indirect
117-
google.golang.org/grpc v1.47.0 // indirect
130+
google.golang.org/grpc v1.48.0 // indirect
118131
gopkg.in/yaml.v2 v2.4.0 // indirect
119132
gorm.io/driver/mysql v1.3.2 // indirect
120133
)

0 commit comments

Comments
 (0)