Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions bigquery/routine.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func (r *Routine) Create(ctx context.Context, rm *RoutineMetadata) (err error) {
DatasetId: r.DatasetID,
RoutineId: r.RoutineID,
}
ctx = setDatasetItemTraceMetadata(ctx, r.ProjectID, r.DatasetID, "routines")
req := r.c.bqs.Routines.Insert(r.ProjectID, r.DatasetID, routine).Context(ctx)
setClientHeader(req.Header())
_, err = req.Do()
Expand All @@ -92,6 +93,7 @@ func (r *Routine) Metadata(ctx context.Context) (rm *RoutineMetadata, err error)
ctx = trace.StartSpan(ctx, "cloud.google.com/go/bigquery.Routine.Metadata")
defer func() { trace.EndSpan(ctx, err) }()

ctx = setRoutineTraceMetadata(ctx, r.ProjectID, r.DatasetID, r.RoutineID)
req := r.c.bqs.Routines.Get(r.ProjectID, r.DatasetID, r.RoutineID).Context(ctx)
setClientHeader(req.Header())
var routine *bq.Routine
Expand Down Expand Up @@ -123,6 +125,7 @@ func (r *Routine) Update(ctx context.Context, upd *RoutineMetadataToUpdate, etag
RoutineId: r.RoutineID,
}

ctx = setRoutineTraceMetadata(ctx, r.ProjectID, r.DatasetID, r.RoutineID)
call := r.c.bqs.Routines.Update(r.ProjectID, r.DatasetID, r.RoutineID, bqr).Context(ctx)
setClientHeader(call.Header())
if etag != "" {
Expand All @@ -145,6 +148,7 @@ func (r *Routine) Delete(ctx context.Context) (err error) {
ctx = trace.StartSpan(ctx, "cloud.google.com/go/bigquery.Model.Delete")
defer func() { trace.EndSpan(ctx, err) }()

ctx = setRoutineTraceMetadata(ctx, r.ProjectID, r.DatasetID, r.RoutineID)
req := r.c.bqs.Routines.Delete(r.ProjectID, r.DatasetID, r.RoutineID).Context(ctx)
setClientHeader(req.Header())
return req.Do()
Expand Down
4 changes: 4 additions & 0 deletions bigquery/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,7 @@ func (t *Table) Create(ctx context.Context, tm *TableMetadata) (err error) {
TableId: t.TableID,
}

ctx = setDatasetItemTraceMetadata(ctx, t.ProjectID, t.DatasetID, "tables")
req := t.c.bqs.Tables.Insert(t.ProjectID, t.DatasetID, table).Context(ctx)
setClientHeader(req.Header())
return runWithRetry(ctx, func() (err error) {
Expand Down Expand Up @@ -935,6 +936,7 @@ func (t *Table) Metadata(ctx context.Context, opts ...TableMetadataOption) (md *
ctx = trace.StartSpan(ctx, "cloud.google.com/go/bigquery.Table.Metadata")
defer func() { trace.EndSpan(ctx, err) }()

ctx = setTableTraceMetadata(ctx, t.ProjectID, t.DatasetID, t.TableID)
tgc := &tableGetCall{
call: t.c.bqs.Tables.Get(t.ProjectID, t.DatasetID, t.TableID).Context(ctx),
}
Expand Down Expand Up @@ -1028,6 +1030,7 @@ func (t *Table) Delete(ctx context.Context) (err error) {
ctx = trace.StartSpan(ctx, "cloud.google.com/go/bigquery.Table.Delete")
defer func() { trace.EndSpan(ctx, err) }()

ctx = setTableTraceMetadata(ctx, t.ProjectID, t.DatasetID, t.TableID)
call := t.c.bqs.Tables.Delete(t.ProjectID, t.DatasetID, t.TableID).Context(ctx)
setClientHeader(call.Header())

Expand Down Expand Up @@ -1084,6 +1087,7 @@ func (t *Table) Update(ctx context.Context, tm TableMetadataToUpdate, etag strin
return nil, err
}

ctx = setTableTraceMetadata(ctx, t.ProjectID, t.DatasetID, t.TableID)
tpc := &tablePatchCall{
call: t.c.bqs.Tables.Patch(t.ProjectID, t.DatasetID, t.TableID, bqt).Context(ctx),
}
Expand Down
30 changes: 30 additions & 0 deletions bigquery/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,33 @@ func setModelTraceMetadata(ctx context.Context, projectID, datasetID, modelID st
modelResourceName(projectID, datasetID, modelID),
"/bigquery/v2/projects/{projectId}/datasets/{datasetId}/models/{modelId}")
}

// tableResourceName constructs the standard resource name for a table.
// E.g., "//bigquery.googleapis.com/projects/{project}/datasets/{dataset}/tables/{table}"
func tableResourceName(projectID, datasetID, tableID string) string {
return fmt.Sprintf("//bigquery.googleapis.com/projects/%s/datasets/%s/tables/%s", projectID, datasetID, tableID)
}

// routineResourceName constructs the standard resource name for a routine.
// E.g., "//bigquery.googleapis.com/projects/{project}/datasets/{dataset}/routines/{routine}"
func routineResourceName(projectID, datasetID, routineID string) string {
return fmt.Sprintf("//bigquery.googleapis.com/projects/%s/datasets/%s/routines/%s", projectID, datasetID, routineID)
}

func setTableTraceMetadata(ctx context.Context, projectID, datasetID, tableID string) context.Context {
if !gax.IsFeatureEnabled("TRACING") {
return ctx
}
return setTraceMetadata(ctx,
tableResourceName(projectID, datasetID, tableID),
"/bigquery/v2/projects/{projectId}/datasets/{datasetId}/tables/{tableId}")
}

func setRoutineTraceMetadata(ctx context.Context, projectID, datasetID, routineID string) context.Context {
if !gax.IsFeatureEnabled("TRACING") {
return ctx
}
return setTraceMetadata(ctx,
routineResourceName(projectID, datasetID, routineID),
"/bigquery/v2/projects/{projectId}/datasets/{datasetId}/routines/{routineId}")
}
Loading
Loading