Skip to content

Commit

Permalink
Added tracking for OAuth client ID in analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin committed Jul 16, 2014
1 parent c745a89 commit c830ef5
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type AnalyticsRecord struct {
APIName string
APIID string
OrgID string
OauthID string
}

// AnalyticsError is an error for when writing to the storage engine fails
Expand Down
5 changes: 4 additions & 1 deletion handler_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ func (e ErrorHandler) HandleError(w http.ResponseWriter, r *http.Request, err st
r.URL.Path = strings.Replace(r.URL.Path, e.TykMiddleware.Spec.Proxy.ListenPath, "", 1)
}

thisSessionState := context.Get(r, SessionData).(SessionState)

thisRecord := AnalyticsRecord{
r.Method,
r.URL.Path,
Expand All @@ -49,7 +51,8 @@ func (e ErrorHandler) HandleError(w http.ResponseWriter, r *http.Request, err st
version,
e.Spec.APIDefinition.Name,
e.Spec.APIDefinition.APIID,
e.Spec.APIDefinition.OrgID}
e.Spec.APIDefinition.OrgID,
thisSessionState.OauthClientID}
analytics.RecordHit(thisRecord)
}

Expand Down
6 changes: 5 additions & 1 deletion handler_success.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ func (s SuccessHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
r.URL.Path = strings.Replace(r.URL.Path, s.Spec.Proxy.ListenPath, "", 1)
}

thisSessionState := context.Get(r, SessionData).(SessionState)


thisRecord := AnalyticsRecord{
r.Method,
r.URL.Path,
Expand All @@ -62,7 +65,8 @@ func (s SuccessHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
version,
s.Spec.APIDefinition.Name,
s.Spec.APIDefinition.APIID,
s.Spec.APIDefinition.OrgID}
s.Spec.APIDefinition.OrgID,
thisSessionState.OauthClientID}
analytics.RecordHit(thisRecord)
}

Expand Down
3 changes: 3 additions & 0 deletions oauth_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ func (r RedisOsinStorageInterface) SaveAccess(accessData *osin.AccessData) error
return unmarshalErr
}

// Set the client ID for analytics
newSession.OauthClientID = accessData.Client.Id

// Override timeouts so that we can be in sync with Osin
newSession.Expires = time.Now().Unix() + int64(accessData.ExpiresIn)

Expand Down
1 change: 1 addition & 0 deletions session_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type SessionState struct {
QuotaRenewalRate int64 `json:"quota_renewal_rate"`
AccessRights map[string]AccessDefinition `json:"access_rights"`
OrgID string `json:"org_id"`
OauthClientID string `json:"oauth_client_id"`
}

// SessionLimiter is the rate limiter for the API, use ForwardMessage() to
Expand Down

0 comments on commit c830ef5

Please sign in to comment.