Skip to content

Commit

Permalink
tracer name changes
Browse files Browse the repository at this point in the history
  • Loading branch information
tolgaOzen committed Dec 23, 2022
1 parent 5dd44c1 commit e4d969a
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 14 deletions.
4 changes: 2 additions & 2 deletions internal/commands/lookupEntity.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewLookupEntityCommand(ck ICheckCommand, sr repositories.SchemaReader, rr r

// Execute -
func (command *LookupEntityCommand) Execute(ctx context.Context, request *base.PermissionLookupEntityRequest) (response *base.PermissionLookupEntityResponse, err error) {
ctx, span := tracer.Start(ctx, "permissions.LookUpSchema.execute")
ctx, span := tracer.Start(ctx, "permissions.lookup-entity.execute")
defer span.End()

if request.GetMetadata().GetSnapToken() == "" {
Expand Down Expand Up @@ -66,7 +66,7 @@ func (command *LookupEntityCommand) Execute(ctx context.Context, request *base.P

// Stream -
func (command *LookupEntityCommand) Stream(ctx context.Context, request *base.PermissionLookupEntityRequest, server base.Permission_LookupEntityStreamServer) (err error) {
ctx, span := tracer.Start(ctx, "permissions.LookupEntity.stream")
ctx, span := tracer.Start(ctx, "permissions.lookup-entity.stream")
defer span.End()

if request.GetMetadata().GetSnapToken() == "" {
Expand Down
2 changes: 1 addition & 1 deletion internal/commands/lookupSchema.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewLookupSchemaCommand(schemaReader repositories.SchemaReader) *LookupSchem

// Execute -
func (command *LookupSchemaCommand) Execute(ctx context.Context, request *base.PermissionLookupSchemaRequest) (*base.PermissionLookupSchemaResponse, error) {
ctx, span := tracer.Start(ctx, "permissions.LookupSchema.execute")
ctx, span := tracer.Start(ctx, "permissions.lookup-schema.execute")
defer span.End()

var err error
Expand Down
8 changes: 7 additions & 1 deletion internal/repositories/postgres/relationshipReader.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewRelationshipReader(database *db.Postgres) *RelationshipReader {

// QueryRelationships - Gets all relationships for a given filter
func (r *RelationshipReader) QueryRelationships(ctx context.Context, filter *base.TupleFilter, t string) (database.ITupleCollection, error) {
ctx, span := tracer.Start(ctx, "relationships.read")
ctx, span := tracer.Start(ctx, "relationship-reader.query-relationships")
defer span.End()

var err error
Expand Down Expand Up @@ -97,6 +97,9 @@ func (r *RelationshipReader) QueryRelationships(ctx context.Context, filter *bas

// GetUniqueEntityIDsByEntityType - Gets all unique entity ids for a given entity type
func (r *RelationshipReader) GetUniqueEntityIDsByEntityType(ctx context.Context, typ, t string) (ids []string, err error) {
ctx, span := tracer.Start(ctx, "relationship-reader.get-unique-entity-ids-by-entity_type")
defer span.End()

var st token.SnapToken
st, err = snapshot.EncodedToken{Value: t}.Decode()
if err != nil {
Expand Down Expand Up @@ -146,6 +149,9 @@ func (r *RelationshipReader) GetUniqueEntityIDsByEntityType(ctx context.Context,

// HeadSnapshot - Gets the latest token
func (r *RelationshipReader) HeadSnapshot(ctx context.Context) (token.SnapToken, error) {
ctx, span := tracer.Start(ctx, "relationship-reader.head-snapshot")
defer span.End()

var xid types.XID8
query := r.database.Builder.Select("id").From(TransactionsTable).OrderBy("id DESC").Limit(1)
sql, args, err := query.ToSql()
Expand Down
5 changes: 4 additions & 1 deletion internal/repositories/postgres/relationshipWriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ func NewRelationshipWriter(database *db.Postgres) *RelationshipWriter {

// WriteRelationships - Writes a collection of relationships to the database
func (w *RelationshipWriter) WriteRelationships(ctx context.Context, collection database.ITupleCollection) (token.EncodedSnapToken, error) {
ctx, span := tracer.Start(ctx, "relationship-writer.write-relationships")
defer span.End()

for i := 0; i <= 10; i++ {
tx, bErr := w.database.Pool.BeginTx(ctx, w.txOptions)
if bErr != nil {
Expand Down Expand Up @@ -88,7 +91,7 @@ func (w *RelationshipWriter) WriteRelationships(ctx context.Context, collection

// DeleteRelationships - Deletes a collection of relationships to the database
func (w *RelationshipWriter) DeleteRelationships(ctx context.Context, filter *base.TupleFilter) (token.EncodedSnapToken, error) {
ctx, span := tracer.Start(ctx, "relationships.delete")
ctx, span := tracer.Start(ctx, "relationship-writer.delete-relationships")
defer span.End()

for i := 0; i <= 10; i++ {
Expand Down
7 changes: 5 additions & 2 deletions internal/repositories/postgres/schemaReader.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func NewSchemaReader(database *db.Postgres) *SchemaReader {

// ReadSchema - Reads entity config from the repository.
func (r *SchemaReader) ReadSchema(ctx context.Context, version string) (schema *base.IndexedSchema, err error) {
ctx, span := tracer.Start(ctx, "schema-reader.read-schema")
defer span.End()

tx, err := r.database.Pool.BeginTx(ctx, r.txOptions)
if err != nil {
return nil, err
Expand Down Expand Up @@ -76,7 +79,7 @@ func (r *SchemaReader) ReadSchema(ctx context.Context, version string) (schema *

// ReadSchemaDefinition - Reads entity config from the repository.
func (r *SchemaReader) ReadSchemaDefinition(ctx context.Context, entityType, version string) (*base.EntityDefinition, string, error) {
ctx, span := tracer.Start(ctx, "schemaReader.read.definition")
ctx, span := tracer.Start(ctx, "schema-reader.read-schema-definition")
defer span.End()

var err error
Expand Down Expand Up @@ -127,7 +130,7 @@ func (r *SchemaReader) ReadSchemaDefinition(ctx context.Context, entityType, ver

// HeadVersion - Finds the latest version of the schema.
func (r *SchemaReader) HeadVersion(ctx context.Context) (version string, err error) {
ctx, span := tracer.Start(ctx, "schemaReader.read.head")
ctx, span := tracer.Start(ctx, "schema-reader.head-version")
defer span.End()

var sql string
Expand Down
2 changes: 1 addition & 1 deletion internal/repositories/postgres/schemaWriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewSchemaWriter(database *db.Postgres) *SchemaWriter {

// WriteSchema writes a schema to the database
func (w *SchemaWriter) WriteSchema(ctx context.Context, schemas []repositories.SchemaDefinition) (string, error) {
ctx, span := tracer.Start(ctx, "schemas.write.save")
ctx, span := tracer.Start(ctx, "schema-writer.write-schema")
defer span.End()

id := xid.New()
Expand Down
2 changes: 1 addition & 1 deletion internal/repositories/postgres/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import (
"go.opentelemetry.io/otel"
)

var tracer = otel.Tracer("postgres")
var tracer = otel.Tracer("repositories.postgres")
8 changes: 4 additions & 4 deletions internal/servers/permissionServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (r *PermissionServer) Check(ctx context.Context, request *v1.PermissionChec

// Expand - Get schema actions in a tree structure
func (r *PermissionServer) Expand(ctx context.Context, request *v1.PermissionExpandRequest) (*v1.PermissionExpandResponse, error) {
ctx, span := tracer.Start(ctx, "permissions.expand")
ctx, span := tracer.Start(ctx, "expand")
defer span.End()

v := request.Validate()
Expand All @@ -74,7 +74,7 @@ func (r *PermissionServer) Expand(ctx context.Context, request *v1.PermissionExp

// LookupSchema -
func (r *PermissionServer) LookupSchema(ctx context.Context, request *v1.PermissionLookupSchemaRequest) (*v1.PermissionLookupSchemaResponse, error) {
ctx, span := tracer.Start(ctx, "permissions.lookupSchema")
ctx, span := tracer.Start(ctx, "lookup-schema")
defer span.End()

v := request.Validate()
Expand All @@ -97,7 +97,7 @@ func (r *PermissionServer) LookupSchema(ctx context.Context, request *v1.Permiss

// LookupEntity -
func (r *PermissionServer) LookupEntity(ctx context.Context, request *v1.PermissionLookupEntityRequest) (*v1.PermissionLookupEntityResponse, error) {
ctx, span := tracer.Start(ctx, "permissions.lookupEntity")
ctx, span := tracer.Start(ctx, "lookup-entity")
defer span.End()

v := request.Validate()
Expand All @@ -120,7 +120,7 @@ func (r *PermissionServer) LookupEntity(ctx context.Context, request *v1.Permiss

// LookupEntityStream -
func (r *PermissionServer) LookupEntityStream(request *v1.PermissionLookupEntityRequest, server v1.Permission_LookupEntityStreamServer) error {
ctx, span := tracer.Start(context.Background(), "permissions.lookupEntityStream")
ctx, span := tracer.Start(context.Background(), "lookup-entity-stream")
defer span.End()

v := request.Validate()
Expand Down
6 changes: 6 additions & 0 deletions internal/services/relationshipService.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ func NewRelationshipService(rr repositories.RelationshipReader, rw repositories.

// ReadRelationships -
func (service *RelationshipService) ReadRelationships(ctx context.Context, filter *base.TupleFilter, token string) (tuples database.ITupleCollection, err error) {
ctx, span := tracer.Start(ctx, "relationships.read")
defer span.End()

return service.rr.QueryRelationships(ctx, filter, token)
}

Expand Down Expand Up @@ -89,5 +92,8 @@ func (service *RelationshipService) WriteRelationships(ctx context.Context, tupl

// DeleteRelationships -
func (service *RelationshipService) DeleteRelationships(ctx context.Context, filter *base.TupleFilter) (token.EncodedSnapToken, error) {
ctx, span := tracer.Start(ctx, "relationships.delete")
defer span.End()

return service.rw.DeleteRelationships(ctx, filter)
}
5 changes: 4 additions & 1 deletion internal/services/schemaService.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ func NewSchemaService(sw repositories.SchemaWriter, sr repositories.SchemaReader

// ReadSchema -
func (service *SchemaService) ReadSchema(ctx context.Context, version string) (response *base.IndexedSchema, err error) {
ctx, span := tracer.Start(ctx, "schemas.read")
defer span.End()

if version == "" {
var ver string
ver, err = service.sr.HeadVersion(ctx)
Expand All @@ -43,7 +46,7 @@ func (service *SchemaService) ReadSchema(ctx context.Context, version string) (r

// WriteSchema -
func (service *SchemaService) WriteSchema(ctx context.Context, schema string) (response string, err error) {
ctx, span := tracer.Start(ctx, "schemas.write.parse")
ctx, span := tracer.Start(ctx, "schemas.write")
defer span.End()

sch, err := parser.NewParser(schema).Parse()
Expand Down

0 comments on commit e4d969a

Please sign in to comment.