Skip to content

Commit 18176cd

Browse files
committed
Add top-level spans
1 parent 8b146ba commit 18176cd

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

internal/scti/handlers.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,14 +345,23 @@ func addChainInternal(ctx context.Context, opts *HandlerOptions, log *log, w htt
345345
}
346346

347347
func addChain(ctx context.Context, opts *HandlerOptions, log *log, w http.ResponseWriter, r *http.Request) (int, error) {
348+
ctx, span := tracer.Start(ctx, "tesseract.addChain")
349+
defer span.End()
350+
348351
return addChainInternal(ctx, opts, log, w, r, false)
349352
}
350353

351354
func addPreChain(ctx context.Context, opts *HandlerOptions, log *log, w http.ResponseWriter, r *http.Request) (int, error) {
355+
ctx, span := tracer.Start(ctx, "tesseract.addPreChain")
356+
defer span.End()
357+
352358
return addChainInternal(ctx, opts, log, w, r, true)
353359
}
354360

355-
func getRoots(_ context.Context, opts *HandlerOptions, log *log, w http.ResponseWriter, _ *http.Request) (int, error) {
361+
func getRoots(ctx context.Context, opts *HandlerOptions, log *log, w http.ResponseWriter, _ *http.Request) (int, error) {
362+
_, span := tracer.Start(ctx, "tesseract.getRoots")
363+
defer span.End()
364+
356365
// Pull out the raw certificates from the parsed versions
357366
rawCerts := make([][]byte, 0, len(log.chainValidationOpts.trustedRoots.RawCertificates()))
358367
for _, cert := range log.chainValidationOpts.trustedRoots.RawCertificates() {

storage/otel.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2025 The Tessera authors. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package storage
16+
17+
import (
18+
"go.opentelemetry.io/otel"
19+
)
20+
21+
const name = "github.com/transparency-dev/static-ct/storage"
22+
23+
var (
24+
tracer = otel.Tracer(name)
25+
)

storage/storage.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ func NewCTStorage(logStorage *tessera.Appender, issuerStorage IssuerStorage, ded
6868

6969
// Add stores CT entries.
7070
func (cts *CTStorage) Add(ctx context.Context, entry *ctonly.Entry) tessera.IndexFuture {
71+
ctx, span := tracer.Start(ctx, "tesseract.storage.Add")
72+
defer span.End()
73+
7174
// TODO(phboneff): add deduplication and chain storage
7275
return cts.storeData(ctx, entry)
7376
}
@@ -76,6 +79,9 @@ func (cts *CTStorage) Add(ctx context.Context, entry *ctonly.Entry) tessera.Inde
7679
//
7780
// If an object is already stored under this hash, continues.
7881
func (cts *CTStorage) AddIssuerChain(ctx context.Context, chain []*x509.Certificate) error {
82+
ctx, span := tracer.Start(ctx, "tesseract.storage.AddIssuerChain")
83+
defer span.End()
84+
7985
kvs := []KV{}
8086
for _, c := range chain {
8187
id := sha256.Sum256(c.Raw)
@@ -125,6 +131,9 @@ func cachedStoreIssuers(s IssuerStorage) func(context.Context, []KV) error {
125131

126132
// AddCertDedupInfo stores <cert_hash, SCTDedupInfo> in the deduplication storage.
127133
func (cts CTStorage) AddCertDedupInfo(ctx context.Context, c *x509.Certificate, sctDedupInfo dedup.SCTDedupInfo) error {
134+
ctx, span := tracer.Start(ctx, "tesseract.storage.AddCertDedupInfo")
135+
defer span.End()
136+
128137
key := sha256.Sum256(c.Raw)
129138
if err := cts.dedupStorage.Add(ctx, []dedup.LeafDedupInfo{{LeafID: key[:], SCTDedupInfo: sctDedupInfo}}); err != nil {
130139
return fmt.Errorf("error storing SCTDedupInfo %+v of \"%x\": %v", sctDedupInfo, key, err)
@@ -134,6 +143,9 @@ func (cts CTStorage) AddCertDedupInfo(ctx context.Context, c *x509.Certificate,
134143

135144
// GetCertDedupInfo fetches the SCTDedupInfo of a given certificate from the deduplication storage.
136145
func (cts CTStorage) GetCertDedupInfo(ctx context.Context, c *x509.Certificate) (dedup.SCTDedupInfo, bool, error) {
146+
ctx, span := tracer.Start(ctx, "tesseract.storageGetCertDedupInfo")
147+
defer span.End()
148+
137149
key := sha256.Sum256(c.Raw)
138150
sctC, ok, err := cts.dedupStorage.Get(ctx, key[:])
139151
if err != nil {

0 commit comments

Comments
 (0)