Skip to content

[feature] Automatic aggregation of traces without parent span #108

Closed

Description

@AtlanCI

Question

In the latest version if no span is given before the sql operation is executed, then the span of the sql execution operation will be scattered.

example :

Modify the query function in the example package to the following

func query(db *sql.DB) error {
	// Create a span
	//tracer := otel.GetTracerProvider()
	//ctx, span := tracer.Tracer(instrumentationName).Start(context.Background(), "example")
	//defer span.End()
	ctx := context.Background()
	// Make a query
	rows, err := db.QueryContext(ctx, `SELECT CURRENT_TIMESTAMP()`)
	if err != nil {
		return err
	}
	defer rows.Close()

	var currentTime time.Time
	for rows.Next() {
		err = rows.Scan(&currentTime)
		if err != nil {
			return err
		}
	}
	fmt.Println(currentTime)
	return nil
}

result

image

Requirement

There is no way to realize that if the upper layer does not pass the parent span, I become the parent span myself. To achieve automatic aggregation of scattered spans.

Activity

  1. added
    enhancement
    on Jul 28, 2022
  2. XSAM commented on Jul 28, 2022

    @XSAM
    Owner

    sql.rows is not a child of sql.conn.query, or you will see weird spans in which the child span starts where the parent span ends.

    # A is the parent of B
    
    A span: start --- end
                         |
    B span:               start --- end
    

    So, there is no need to aggregate these spans even though they are the root span.

  3. AtlanCI commented on Jul 28, 2022

    @AtlanCI
    Author

    I've thought about it for a while and if the user doesn't provide the parent span there is no way to aggregate perfectly. The standard library sql is not a tree model, somewhat similar to a forest.
    Users do not execute sql through the same portal

    I will close the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions