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

feat: Implement otel tracing hook. #130

Merged
merged 33 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
a54c2d1
feat: Implement supporting types for hooks. (#125)
kinyoklion Mar 28, 2024
f93d96c
feat: Add support for hooks. (#126)
kinyoklion Mar 28, 2024
1c56855
feat: Implement otel tracing hook.
kinyoklion Mar 28, 2024
b735744
chore(refactor): Remove AddHooks, refactor execution, add contract te…
kinyoklion Mar 29, 2024
84f86f0
Merge branch 'feat/hooks' into rlamb/implement-otel-hook
kinyoklion Mar 29, 2024
150d09e
Loop based targets and update contributing.
kinyoklion Mar 29, 2024
4ab744a
Add comment to makefile
kinyoklion Mar 29, 2024
b041730
Support all targets in makefile.
kinyoklion Apr 1, 2024
152107d
Update .PHONY
kinyoklion Apr 1, 2024
722f7b2
Add experimental text.
kinyoklion Apr 1, 2024
745c08c
Add use separate releases.
kinyoklion Apr 1, 2024
b8ec2b6
Tidy
kinyoklion Apr 1, 2024
b749180
Reformat example.
kinyoklion Apr 1, 2024
7806865
Re-add clean.
kinyoklion Apr 2, 2024
8c9d529
Change ldmodule path
kinyoklion Apr 2, 2024
f493f46
Remove blank line.
kinyoklion Apr 2, 2024
78d794c
Merge branch 'v7' into rlamb/implement-otel-hook
kinyoklion Apr 3, 2024
51f15d5
Update version of go server SDK used.
kinyoklion Apr 3, 2024
7d99137
Update makefile to work regardless of workspace.
kinyoklion Apr 3, 2024
b21bd61
Attempt at CI.
kinyoklion Apr 3, 2024
d9a0493
No contract tests for ldotel.
kinyoklion Apr 3, 2024
57056a9
Conditions.
kinyoklion Apr 3, 2024
cad7c92
Split testing.
kinyoklion Apr 3, 2024
f7455cf
Fix name
kinyoklion Apr 3, 2024
e5a7bc9
Cleanup name.
kinyoklion Apr 3, 2024
7199460
Fix base CI workflow.
kinyoklion Apr 3, 2024
ac70cab
Add readme.
kinyoklion Apr 3, 2024
ec7d52d
Issue templates
kinyoklion Apr 3, 2024
0c7461f
Remove extra links.
kinyoklion Apr 3, 2024
beb9a75
Unique test result files.
kinyoklion Apr 3, 2024
eeae3e5
Go version from matrix.
kinyoklion Apr 3, 2024
509a5e0
Update .github/ISSUE_TEMPLATE/bug_report--ldotel.md
kinyoklion Apr 10, 2024
c07f7a2
Update .github/ISSUE_TEMPLATE/bug_report--ldotel.md
kinyoklion Apr 10, 2024
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
37 changes: 37 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report--ldotel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
name: Bug report for the ldotel module
about: Create a report to help us improve
title: ''
labels: 'ldotel, enhancement'
assignees: ''

---

**Is this a support request?**
This issue tracker is maintained by LaunchDarkly SDK developers and is intended for feedback on the SDK code. If you're not sure whether the problem you are having is specifically related to the SDK, or to the LaunchDarkly service overall, it may be more appropriate to contact the LaunchDarkly support team; they can help to investigate the problem and will consult the SDK team if necessary. You can submit a support request by going [here](https://support.launchdarkly.com/hc/en-us/requests/new) or by emailing support@launchdarkly.com.

Note that issues filed on this issue tracker are publicly accessible. Do not provide any private account information on your issues. If your problem is specific to your account, you should submit a support request as described above.

**Describe the bug**
A clear and concise description of what the bug is.

**To reproduce**
Steps to reproduce the behavior.

**Expected behavior**
A clear and concise description of what you expected to happen.

**Logs**
If applicable, add any log output related to your problem.

**SDK version**
The version of this SDK that you are using.

**Language version, developer tools**
For instance, Go 1.22.

**OS/platform**
For instance, Ubuntu 16.04, or Windows 10.

**Additional context**
Add any other context about the problem here.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
labels: 'server-sdk, bug'
assignees: ''

---
Expand Down
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request--ldotel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request for the ldotel module
about: Suggest an idea for this project
title: ''
labels: 'ldotel, enhancement'
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I would love to see the SDK [...does something new...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context about the feature request here.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
labels: 'server-sdk, enhancement'
assignees: ''

---
Expand Down
7 changes: 5 additions & 2 deletions .github/actions/unit-tests/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ inputs:
description: 'Whether to run linters.'
required: false
default: 'false'
test-target:
description: 'The test target to run.'
required: true

runs:
using: composite
Expand All @@ -19,7 +22,7 @@ runs:
- name: Test
shell: bash
id: test
run: make test | tee raw_report.txt
run: make ${{ inputs.test-target }} | tee raw_report.txt

- name: Process test results
if: steps.test.outcome == 'success'
Expand All @@ -31,5 +34,5 @@ runs:
if: steps.process-test.outcome == 'success'
uses: actions/upload-artifact@v4
with:
name: Test-result-${{ steps.go-version.outputs.version }}
name: Test-result-${{ inputs.test-target }}${{ steps.go-version.outputs.version }}
path: junit_report.xml
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and Test
name: Build and Test SDK
on:
push:
branches: [ 'v7', 'feat/**' ]
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/common_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ on:
required: true
type: string


jobs:
unit-test-and-coverage:
runs-on: ubuntu-latest
Expand All @@ -21,6 +20,7 @@ jobs:
- uses: ./.github/actions/unit-tests
with:
lint: 'true'
test-target: sdk-test
- uses: ./.github/actions/coverage
with:
enforce: 'false'
Expand Down Expand Up @@ -51,8 +51,6 @@ jobs:
name: Contract-test-service-logs-${{ steps.go-version.outputs.version }}
path: /tmp/sdk-contract-test-service.log



benchmarks:
name: 'Benchmarks'
runs-on: ubuntu-latest
Expand Down
38 changes: 38 additions & 0 deletions .github/workflows/ldotel-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Build and Test ldotel
on:
push:
branches: [ 'v7', 'feat/**' ]
paths-ignore:
- '**.md' # Don't run CI on markdown changes.
pull_request:
branches: [ 'v7', 'feat/**' ]
paths-ignore:
- '**.md'

jobs:
go-versions:
uses: ./.github/workflows/go-versions.yml

# Runs the common tasks (unit tests, lint, contract tests) for each Go version.
test-linux:
name: ${{ format('ldotel Linux, Go {0}', matrix.go-version) }}
needs: go-versions
strategy:
# Let jobs fail independently, in case it's a single version that's broken.
fail-fast: false
matrix:
go-version: ${{ fromJSON(needs.go-versions.outputs.matrix) }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Go ${{ inputs.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- uses: ./.github/actions/unit-tests
with:
lint: 'true'
test-target: ldotel-test
- uses: ./.github/actions/coverage
with:
enforce: 'false'
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ go-server-sdk.test
allocations.out
.idea
.vscode
go.work
go.work.sum
31 changes: 21 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,39 @@ This project should be built against the lowest supported Go version as describe

### Building

To build the SDK without running any tests:
```
To build all modules without running any tests:
```shell
make
```

If you wish to clean your working directory between builds, you can clean it by running:
```
make clean
```

To run the linter:
```
```shell
make lint
```

### Testing

To build the SDK and run all unit tests:
```
To build all modules and run all unit tests:
```shell
make test
```

### Clean

To clean temporary files created by other targets:
```shell
make clean
```

### Working Cross Module

If you have a change which affects more than a single module, then you can use a go workspace.

You can create a workspace using:
```shell
make workspace
```

## Coding best practices

The Go SDK can be used in high-traffic application/service code where performance is critical. There are a number of coding principles to keep in mind for maximizing performance. The benchmarks that are run in CI are helpful in measuring the impact of code changes in this regard.
Expand Down
70 changes: 59 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ GOLANGCI_LINT_VERSION=v1.57.1
LINTER=./bin/golangci-lint
LINTER_VERSION_FILE=./bin/.golangci-lint-version-$(GOLANGCI_LINT_VERSION)

GO_WORK_FILE=go.work
GO_WORK_SUM=go.work.sum

TEST_BINARY=./go-server-sdk.test
ALLOCATIONS_LOG=./build/allocations.out

Expand All @@ -20,22 +23,59 @@ COVERAGE_ENFORCER_FLAGS=-package github.com/launchdarkly/go-server-sdk/v7 \
-skipcode "// COVERAGE" \
-packagestats -filestats -showcode

.PHONY: build clean test test-coverage benchmarks benchmark-allocs lint
ALL_BUILD_TARGETS=sdk ldotel
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add the test service? It does not pass linting right now, because it doesn't seem to have accounted for the nested modules not working with ./....

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going with no. We can add it to linting later, but fixing all its lint problems will need a PR as well.

ALL_TEST_TARGETS = $(addsuffix -test, $(ALL_BUILD_TARGETS))
ALL_LINT_TARGETS = $(addsuffix -lint, $(ALL_BUILD_TARGETS))

kinyoklion marked this conversation as resolved.
Show resolved Hide resolved
build:
go build ./...
.PHONY: all build clean test test-coverage benchmarks benchmark-allocs lint workspace workspace-clean $(ALL_BUILD_TARGETS) $(ALL_TEST_TARGETS) $(ALL_LINT_TARGETS)

all: $(ALL_BUILD_TARGETS)

test: $(ALL_TEST_TARGETS)

clean:
go clean
clean: workspace-clean
rm -rf ./bin/

test:
go test -run=not-a-real-test ./... # just ensures that the tests compile
sdk:
go build ./...

sdk-test:
go test -v -race ./...
@# The proxy tests must be run separately because Go caches the global proxy environment variables. We use
@# build tags to isolate these tests from the main test run so that if you do "go test ./..." you won't
@# get unexpected errors.
for tag in proxytest1 proxytest2; do go test -race -v -tags=$$tag ./proxytest; done

sdk-lint:
$(LINTER) run ./...

ldotel:
@if [ -f go.work ]; then \
echo "Building ldotel with workspace" \
go build ./ldotel; \
else \
echo "Building ldotel without workspace" \
cd ldotel && go build .; \
fi

ldotel-test:
@if [ -f go.work ]; then \
echo "Testing ldotel with workspace" \
go test -v -race ./ldotel; \
else \
echo "Testing ldotel without workspace" \
cd ldotel && go test -v -race .; \
fi

ldotel-lint:
@if [ -f go.work ]; then \
echo "Linting ldotel with workspace" \
$(LINTER) run ./ldotel; \
else \
echo "Linting ldotel without workspace" \
cd ldotel && $(LINTER) run .; \
fi

test-coverage: $(COVERAGE_PROFILE_RAW)
go run github.com/launchdarkly-labs/go-coverage-enforcer@latest $(COVERAGE_ENFORCER_FLAGS) -outprofile $(COVERAGE_PROFILE_FILTERED) $(COVERAGE_PROFILE_RAW)
go tool cover -html $(COVERAGE_PROFILE_FILTERED) -o $(COVERAGE_PROFILE_FILTERED_HTML)
Expand Down Expand Up @@ -70,17 +110,25 @@ $(LINTER_VERSION_FILE):
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s $(GOLANGCI_LINT_VERSION)
touch $(LINTER_VERSION_FILE)

lint: $(LINTER_VERSION_FILE)
$(LINTER) run ./...

lint: $(LINTER_VERSION_FILE) $(ALL_LINT_TARGETS)

TEMP_TEST_OUTPUT=/tmp/sdk-contract-test-service.log

# TEST_HARNESS_PARAMS can be set to add -skip parameters for any contract tests that cannot yet pass
TEST_HARNESS_PARAMS=

workspace: go.work

go.work:
go work init ./
go work use ./ldotel
go work use ./testservice
kinyoklion marked this conversation as resolved.
Show resolved Hide resolved

workspace-clean:
rm -f $(GO_WORK_FILE) $(GO_WORK_SUM)

build-contract-tests:
@cd testservice && go mod tidy && go build
@go build -o ./testservice/testservice ./testservice

start-contract-test-service: build-contract-tests
@./testservice/testservice
Expand Down
54 changes: 54 additions & 0 deletions ldotel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
LaunchDarkly Server-side OTEL library for Go
==============================================
[![Actions Status](https://github.com/launchdarkly/go-server-sdk/actions/workflows/ldotel-ci.yml/badge.svg?branch=v7)](https://github.com/launchdarkly/go-server-sdk/actions/workflows/ci.yml)

LaunchDarkly overview
-------------------------
[LaunchDarkly](https://www.launchdarkly.com) is a feature management platform that serves trillions of feature flags daily to help teams build better software, faster. [Get started](https://docs.launchdarkly.com/home/getting-started) using LaunchDarkly today!

[![Twitter Follow](https://img.shields.io/twitter/follow/launchdarkly.svg?style=social&label=Follow&maxAge=2592000)](https://twitter.com/intent/follow?screen_name=launchdarkly)

Getting started
-----------

Import the module:

```go
import (
"github.com/launchdarkly/go-server-sdk/ldotel"
)
```

Configure the LaunchDarkly client to use a tracing hook:

```go
client, _ = ld.MakeCustomClient("your-sdk-key",
ld.Config{
Hooks: []ldhooks.Hook{ldotel.NewTracingHook()},
}, 5*time.Second)
```

Learn more
-----------

Read our [documentation](http://docs.launchdarkly.com) for in-depth instructions on configuring and using LaunchDarkly.

Contributing
------------

We encourage pull requests and other contributions from the community. Check out our [contributing guidelines](CONTRIBUTING.md) for instructions on how to contribute to this library.

About LaunchDarkly
-----------

* LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can:
* Roll out a new feature to a subset of your users (like a group of users who opt-in to a beta tester group), gathering feedback and bug reports from real-world use cases.
* Gradually roll out a feature to an increasing percentage of users, and track the effect that the feature has on key metrics (for instance, how likely is a user to complete a purchase if they have feature A versus feature B?).
* Turn off a feature that you realize is causing performance problems in production, without needing to re-deploy, or even restart the application with a changed configuration file.
* Grant access to certain features based on user attributes, like payment plan (eg: users on the ‘gold’ plan get access to more features than users in the ‘silver’ plan). Disable parts of your application to facilitate maintenance, without taking everything offline.
* LaunchDarkly provides feature flag SDKs for a wide variety of languages and technologies. Read [our documentation](https://docs.launchdarkly.com/sdk) for a complete list.
* Explore LaunchDarkly
* [launchdarkly.com](https://www.launchdarkly.com/ "LaunchDarkly Main Website") for more information
* [docs.launchdarkly.com](https://docs.launchdarkly.com/ "LaunchDarkly Documentation") for our documentation and SDK reference guides
* [apidocs.launchdarkly.com](https://apidocs.launchdarkly.com/ "LaunchDarkly API Documentation") for our API documentation
* [blog.launchdarkly.com](https://blog.launchdarkly.com/ "LaunchDarkly Blog Documentation") for the latest product updates
Loading
Loading